I'm trying to write a mongo script from the mongo shell, but I'm having a small problem. I'll let the code explain itself.
var shops = db.Shop.find({})
function printShopUrl(data) {
var name, url;
for (var i = 0; i < data.length(); i++) {
name = data[i].name;
url = db.Instance.findOne({name:name}).url;
print(url);
}
}
printShopUrl(shops)
So all i'm trying to do right now is just to print the url, but when I run this query I get an error.
TypeError: db.Instance.findOne({name:name}) has no properties (shell):1
Any idea what i'm doing wrong?
db.Instance.findOne({name:name})- what do you see?if(result) print(result.url);