Getting an entire array from nested array by giving array name in mongodb

Suppose this is my collection

db.collection.insert([
    {
        "5496":[
            {
                "Asset Name":"HiScanSQ",
                "Chiller Temperature (deg)":"2",
                "Trays Used (nos)":"12",
                "Power (volts)":"123",
                "Pressure (psi)":"15",
                "Usage (hours)":"140",
                "Volume (ml)":"150",
                "Viscosity":"1.8",
                "Cartridge Revolution (rpm)":"1000"
            }
        ]
    },
    {
        "4963":[
            {
                "Asset Name":"Genome Analyzer",
                "Chiller Temperature (deg)":"451",
                "Trays Used (nos)":"3",
                "Power (volts)":"82",
                "Pressure (psi)":"55",
                "Usage (hours)":"280",
                "Volume (ml)":"1000",
                "Viscosity":"1.2",
                "Cartridge Revolution (rpm)":"976"
            }
        ]
    }
]);

How do I fetch the entire array?say entire values of "5496". I need to get all the values related to a particular asset. So if I provide the asset id mongo should return all the asset details.

Answers


Try this:

db.collection.find( {}, { fields: { "5496": 1 }, function( err ,result ) {
    ...
});

db.collection.find( { "5496": { $exists: true } }, { "5496": 1, _id: 0 } ).pretty()
{
        "5496" : [
                {
                        "Asset Name" : "HiScanSQ",
                        "Chiller Temperature (deg)" : "2",
                        "Trays Used (nos)" : "12",
                        "Power (volts)" : "123",
                        "Pressure (psi)" : "15",
                        "Usage (hours)" : "140",
                        "Volume (ml)" : "150",
                        "Viscosity" : "1.8",
                        "Cartridge Revolution (rpm)" : "1000"
                }
        ]
}

Need Your Help

UrlRewriter+HttpModule+Session problem

c# asp.net

I need to write a custom "UrlRewriter" using a HttpModule, in the moment of "rewriting" I need access to the Session and has followed the advice from another SO thread:

Using Socket.IO in C#

javascript c# socket.io

I'm trying to read a Socket.IO stream from Wikimedia sites. There is sample code for various languages, but I need to get this working in C#