I am trying to insert a collection with a json object containing a key which starts with '$
' (for instance: '$count
'). I read the mongodb v3.0 FAQ's and they have mentioned it is not such a key. Is there any roundabout way insert such a key and retrieve it back?
Is not recomanded but you can try this:
dollar = "\uFF04";
$
dot = "\uFF0E"
.
db.test.save({[dollar]:dot})
WriteResult({ "nInserted" : 1 })
db.test.save({[dot]:dollar})
WriteResult({ "nInserted" : 1 })
db.test.find()
{ "_id" : ObjectId("58256b0f9934a5d1c696c456"), "$" : "." }
{ "_id" : ObjectId("58256d359934a5d1c696c457"), "." : "$" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With