Closed krdeepakio closed 9 years ago
RMongo's dbGetQuery()
function is expecting MongoDB Extended JSON syntax for the provided query string.
The MongoDB Extended JSON equivalent of ObjectId("<id>")
is { "$oid": "<id>" }
, so your query should be:
dbGetQueryForKeys(mongo, "tables",
# JSON query
"{'source': { '$oid': '6dc63c46310a3d297c4cc6b4' }}",
# Projection document (fields to return)
"{'source':1}",
# (optional) skip, limit
0, 1
)
Works fine dbGetQueryForKeys(mongo, "tables", "{}", "{'source':1}", 0, 1)
Empty result if I specify a valid query with value of type ObjectId. Both of these give empty result. dbGetQueryForKeys(mongo, "tables", "{'source':'6dc63c46310a3d297c4cc6b4'}", "{'source':1}", 0, 1) dbGetQueryForKeys(mongo, "tables", "{'source':6dc63c46310a3d297c4cc6b4}", "{'source':1}", 0, 1)
'source':ObjectId('...') gives syntax error.