I have this data structure:
{
date: 0,
darwin: [
{
d: ['string1', 1, 0, 0, 0]
},
{
d: ['string2', 1, 0, 0, 0]
},
{
d: ['string3', 1, 0, 0, 0]
}
]
}
and this schema:
const mongoose = require('mongoose');
const { Schema } = mongoose;
const dataSchema = new Schema({
date: { type: Number, required: false, unique: true, index: true },
humanDate: { type: Date, required: false },
darwin: [
{
d: {
type: Array,
required: false
}
}
]
});
module.exports = mongoose.model('data', dataSchema);
I need a list of strings inside "d", i try this
db.getCollection('data').find({date:0},{'darwin.d.$': 1})
but i have this error
Error: error: {
"operationTime" : Timestamp(1635348468, 1),
"ok" : 0,
"errmsg" : "positional operator '.$' couldn't find a matching element in the array",
"code" : 51246,
"codeName" : "Location51246",
"$clusterTime" : {
"clusterTime" : Timestamp(1635348468, 1),
"signature" : {
"hash" : BinData(0,"pfgMUIJkpgjlfnQ6cfiEDpSY+3o="),
"keyId" : NumberLong("7020434099001098244")
}
}}
I have tried several things but I can't get it to get the list of strings, I don't know if I'm applying the '$' operator wrong
I expected some like this
{
date: 0,
darwin: [
{
d: 'string1'
},
{
d: 'string2'
},
{
d: 'string3'
}
]
}