I'm trying to write a mongo script from the mongo shell, but I'm having a small problem. I开发者_如何学Python'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?
Main problem: the following may not return a value db.Instance.findOne({name:name}). Therefore when you add .url, you're trying to get a value from a null.
Try the following:
var obj = db.Instance.findOne({name:name});
if(obj && obj.url) { print(obj.url); }
You have the same potential issue with the name field (name = data[i].name).
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论