louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclude field in array not working?!

Alwinator opened this issue · comments

I tried a basic MongoDB feature:
https://stackoverflow.com/questions/47544446/omit-certain-field-in-an-array-mongo-query

I want to exclude a field inside a array, but unfortunately it does not work in NeDB.

Code example:

const test_db = new Datastore({
    filename: "test",
    autoload: true
})
test_db.insert({
    "fieldA" : "A",
    "fieldB" : "B",
    "fieldC" : [
        { "group1" : "100", "group2" : "200", "id" : "b0a05edd3cb0d35674174f34da1b3021"},
        { "group1" : "110", "group2" : "230", "id" : "b9071b34c21f948e69cb39df7dbf10a7"}
    ]
})
test_db.find({}, {"fieldC.id":0, fieldB: 0, "_id":0}, (err, doc) => {
    console.log(JSON.stringify(doc))
})

Output:

[{"fieldA":"A","fieldC":[{"group1":"100","group2":"200","id":"b0a05edd3cb0d35674174f34da1b3021"},{"group1":"110","group2":"230","id":"b9071b34c21f948e69cb39df7dbf10a7"}]}]

Expected Output:

[{"fieldA":"A","fieldC":[{"group1":"100","group2":"200"},{"group1":"110","group2":"230"]}]