node.js - Insert document with nested ObjectId -


i trying insert document mongodb looks this:

_id : objectid(<id>) players : {     objectid(<id>) {        entry : 'foo'     } } 

however, can't form json in node objectid key. what's best practice this? thanks!

according mongodb documentation:

field names strings.

so can't use objectid's keys, can use string representation:

var playersobj = {}; playersobj[objectid()] = { entry : 'foo' }; // stringify objectid  var document = {   _id     : objectid(),   players : playersobj }; 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -