我嘗試在我的集合「公司」中插入新文檔,並從「用戶」集合中嵌入現有文檔。將現有文檔嵌入到MongoDB的新文檔中
我想什麼是
db.companies.insert({ "_id": 2, name: "sample-com", admin: db.users.find({ "_id": 1 }) })
,但它不工作
「不能在SRC /蒙戈/殼/ collection.js節省的DBQuery對象:143」)
如何將現有文檔嵌入到我的新文檔中?
我嘗試在我的集合「公司」中插入新文檔,並從「用戶」集合中嵌入現有文檔。將現有文檔嵌入到MongoDB的新文檔中
我想什麼是
db.companies.insert({ "_id": 2, name: "sample-com", admin: db.users.find({ "_id": 1 }) })
,但它不工作
「不能在SRC /蒙戈/殼/ collection.js節省的DBQuery對象:143」)
如何將現有文檔嵌入到我的新文檔中?
,您應該使用的.findOne
var admin = db.users.findOne({ "_id": 1 });
db.companies.insert({ "_id": 2, "name": "sample-com", "admin": admin })
可能重複[MongoDB的:JavaScript的執行失敗:在SRC /蒙戈/殼無法保存的DBQuery對象/ collection.js(HTTP://計算器.com/questions/18041356/mongodb-javascript-execution-failed-cant-save-a-dbquery-object-at-src-mongo) – Vishwas