Adding ObjectID manually in MongoDB (Rails/Mong -
i'm working rails 4.0 , mongodb (mongoid) , have following code create documents:
lines.each |l| insert.create(:position => 0, :content => l, :schema_id => moped::bson::objectid.from_string("52419d2f80a9b88bb9000002")) end
this works fine , following output in mongo-database:
{ "_id": { "$oid": "5241ff1280a9b8f16e000057" }, "position": "0", "content": "blabla", "schema_id": "52419d2f80a9b88bb9000002"
}
the problem is, want have "$oid": before actual schema_id this:
... "schema_id": { "$oid": "52419d2f80a9b88bb9000002" }
and got confuse of how can insert "$oid" followed colon manually....
would great if me...
thx in advance!!
you should not have $oid
@ all, neither in schema_id or in _id , make indexing operations hard, or not possible mongodb. have $oid because parsing document json in inserting in db somehow, anyways, if you, write migration fix in db layer, , fix code not use json version before persisting.
Comments
Post a Comment