MongoDB using $returnKey to get Field Name and value -
i have run trouble mongodb. trying value of field, field name not known me , use retrieved value check existence of different document in collection. aware of pattern of value field might containing.
let me explain, have following document structure:
db.blogs_data.find({"_id.r":"http://blog_post_url/authors"}).pretty(); { "_id" : { "r" : "http://blog_post_url/authors" }, "author:_1" : { "u" : "people:c2ce29e7" }, "author:_2" : { "u" : "organisations:0b2a962a-8d1c" }, "rdf:type" : { "u" : "rdf:seq" } }
here author:_2 can : author:_n (numeric). now, details of each sequence in above decument stored separate document, :
db.blogs_data.find({"_id.r":"people:c2ce29e7"}).pretty(); { "_id" : { "r" : "people:c2ce29e7" }, "rdf:type" : { "u" : "foaf:person" }, "foaf:name" : { "l" : "mccabe, catherine" } } db.blogs_data.find({"_id.r":"organisations:0b2a962a-8d1c"}).pretty(); { "_id" : { "r" : "organisations:0b2a962a-8d1c" }, "rdf:type" : { "u" : "foaf:organisations" }, "foaf:name" : { "l" : "abc publications" } }
now, need value of each sequence of /authors, author value pattern : "organisations*", , use value sequence check author details documents, if exists or not. i've checked mongodb, , have $returnkey, says returns index key or keys, http://docs.mongodb.org/v2.2/reference/operator/returnkey/#op._s_returnkey but, document seems incomplete , bit confusing me too, : " if $returnkey set true , query not use index perform read operation, returned documents not contain fields."
well, don't know exact key value is, , value inside it. i've checked mongodb names of keys in collection however, returns unique keys in collection.
it seems me mongo query won't want here, , i've write js script this. there facing same or similar problem? in case of js, should considered starting point?
regards,
i've solved problem :
using regex mongo documents id.r ends /authors, , looping through each author:n inside authors document , use value of author_:n check existence of actual author document.
ravish
Comments
Post a Comment