louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.5k stars 1.03k forks source link

How to get inner data #611

Open dingdong-io opened 5 years ago

dingdong-io commented 5 years ago

demo:

var Datastore = require('nedb')
, db = new Datastore();

db.insert({
    user:{
        user1:{name:'James',goodAt:"basketball"},
        user2:{name:'Curry',goodAt:"basketball"},
    }
})
db.insert({project:['basketball','football']})

db.find({'user.user1.name':'James'},(err,docs)=>{
    console.log(docs)
})
db.find({'user.user1':{name:'James',goodAt:"basketball"}},(err,docs)=>{
    console.log(docs)
})

I just want to get data:{name:'James',goodAt:"basketball"}, but these two method all print [{"user":{"user1":{"name":"James","goodAt":"basketball"},"user2":{"name":"Curry","goodAt":"basketball"}},"_id":"xxx"}].

If it is a big database,I just want to get one user,not return me all user,how can I do?

I feel afraid when I try db.find function, it always return me the outer big data(layer 1), if it's multi layer design, it will be disaster.

chmac commented 5 years ago

The readme says:

IMPORTANT NOTE: Please don't submit issues for questions regarding your code. Only actual bugs or feature requests will be answered, all others will be closed without comment. Also, please follow the bug reporting guidelines and check the change log before submitting an already fixed bug :)

Please close your issue as the author does not answer questions here. You might try stackoverflow.

Bichwaa commented 4 years ago

use findOne, https://github.com/louischatriot/nedb/wiki/Finding-documents, check out this document