db.books.find({ "status": "readED", $and: [ { "listingStatus": { $not: { $exists: true } } } ] }).forEach(function(book){ db.getSiblingDB('reading').bookListing.find({"sellerSku": book.sellerSku, "sellerId":book.seller},{"sellerId": 1, "sellerSku": 1}).forEach(function(bookListing){ printjson(bookListing); }); }); when i run this, it gives
{ "_id" : ObjectId("582cb4ad5a5a380sadas038dd2f72"), "sellerId" : "e0a82c3d-079asdas0-49asda97-aasdascdf-0c320e3d7022", "sellerSku" : "te227" } { "_id" : ObjectId("582cb4ae5a5a380038dd2f73"), "sellerId" : "e0a82casdsa3d-07asdas90-4997-acdf-0c320e3d7022", "sellerSku" : "TE231" } so it means
there are books which is readed and listingstatus is not exist (normally listingstatus must be existed)
in reading db, there is booklisting colletion. Normally what i need to do is:
- if a book readed and listingstatus is not existed, need to update listingstatus if this books sellersku exists in booklisting collection.
instead of
printjson(bookListing); i need to update
book.update(listingstatu) in for each but is that possible in javascript?
What aboout this
db.getSiblingDB('book').books.update({ "seller": bookListing.sellerId, "sellerSku": bookListing.sellerSku },{ $set: {"listingStatus" : "LISTING_CREATED"}}) instead of
printjson(bookListing) it wll again call book db.
but to test i made thi instead of
printjson
db.getSiblingDB('book').books.find({ "seller": bookListing.sellerId, "sellerSku": bookListing.sellerSku },{ $set: {"listingStatus" : "LISTING_CREATED"}}) but it doesnot show anyhing