Il _id =56aea43cb6be380000616b07;
Ho provato a inserire una stringa lunga come 56aea43cb6be380000616b07
al shareids
array in mongodb, ha sempre fallito "token imprevisto illegale".
L'ho provato direttamente con il comando mongo, deve essere "56aea43cb6be380000616b07" per farlo funzionare.
Ma ho controllato il tipo di _id
con typeof
ed è una stringa. Ho provato a impostarlo ObjectID(_id)
ma sempre lo stesso. Come potrei farlo? Grazie.
collection.update({
"name": name
}, {
$push: {
"shareids":
ObjectID(_id)
}}, function (err) {
if (err) {
console.log("update failed.");
mongodb.close();
return callback(err);
}
risposte:
0 per risposta № 1Il "unexpected token illegal"
potrebbe accadere con il seguente comando.
> db.collection.update({name: "test"}, {$push: {shareids: ObjectId(56aea43cb6be380000616b
07)}})
2016-02-01T11:34:35.738+0800 SyntaxError: Unexpected token ILLEGAL
Tuttavia, aggiungi le virgolette a questo numero come qui sotto, andrà bene.
> db.collection.update({name: "test"}, {$push: {shareids: ObjectId("56aea43cb6be380000616
b07")}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })