Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB: javascript execution failed : can't save a DBQuery object at src/mongo/shell/collection.js

In MongoDb , when i try to modify existing document in collection , it generate the following exception : javascript execution failed : can't save a DBQuery object at src/mongo/shell/collection.js

In mongoDb shell i perform the following action :

 > var doc1 = db.users.find({name:"Harmeet"})
 > doc1.color = "Blue"
 > db.users.save(doc1)

when call to the save method the exception thow.

like image 618
Harmeet Singh Taara Avatar asked Aug 04 '13 09:08

Harmeet Singh Taara


2 Answers

Although @Manuel Rony Gomes has answer the question, when you want to insert multiple documents found from collection A into collection B at once, you can use the toArray() to let it work:

db.coll_B.insert(db.coll_A.find({}).toArray())
like image 160
Meng Lee Avatar answered Nov 10 '22 23:11

Meng Lee


use var doc1 = db.users.findOne({name:"Harmeet"})

db.users.find returns a cursor.

like image 34
Manuel Rony Gomes Avatar answered Nov 10 '22 23:11

Manuel Rony Gomes