Mongodb, grouping values only once

I am new to mongodb, I have a collection of people and some of them have a value that I am interested in ("val"). For everyone who has that value, I would like to have a list of another value ("potential") without repeating. { "_id" : 001, "val" : true, "potential", 100} { "_id" :… Read More Mongodb, grouping values only once

mongodb: how to get the length of array with http method?

insert many: [ { comments: [{foo:1}, {foo:1}, {foo:1}, {foo:1}] } { comments: [{foo:1}, {foo:1}] } { comments: [{foo:1}, {foo:1}, {foo:1}, {foo:1}, {foo:1}] } { title: ‘foo’ } { comments: [{foo:1}, {foo:1}, {foo:1}, {foo:1}, {foo:1}, {foo:1}] } ] I am trying to find a method to obtain the length of something from the document. I would… Read More mongodb: how to get the length of array with http method?

MongoDB filter when two fields equal

my data here Does anyone who knows how to filter data and only keep those history_doc.data.objectId equals _id? I have tried so many methods but none of them works {‘history_doc.data.objectId’: {$eq: ‘$_id’}} {‘history_doc.data.objectId’: {$eq: {$toString: ‘$_id’}}} >Solution : You can use $expr and $eq with $toObjectId into aggregation query like this: .aggregate({ $match: { $expr:… Read More MongoDB filter when two fields equal

MongoDB query range date with certain other key

I’ve documents on my collection: {"date_time" : "2022-11-05 09:09:55", "dat1" : "TRUI", "cod" : "XC"} {"date_time" : "2022-11-21 09:09:55","dat1" : "TRQW","cod" : "KL"} {"date_time" : "2022-12-06 09:09:55","dat1" : "CBTR","cod" : "NM"} {"date_time" : "2022-12-18 09:09:55","dat1" : "METR","cod" : "XC"} So, I’d like to query my collection to get all documents with condition "cod" : "XC"… Read More MongoDB query range date with certain other key

Get all strings from array in mongoDb

I am a beginner in node and mongoDb. I send a models from the application to node. const { users } = req.body; console.log(users); and when I print this I have this result. [ ‘{"id":"6389f4206f784a8e3d75cf10","email":"test5@test.com","password":"$2a$08$2cE5XFlShV0nBYS6JF4ckuRLcEvp75YuCazQLSyIZ6bKu5kev/dwS","verify":1,"invitationsToMe":["6390a3b8cb716fa4d67d82d6"],"invitationsFromMe":[],"friendsList":["638777339b32b61a57e5ab4b","638889b46b30846785db55df","638776e89b32b61a57e5ab43","638797306307ba909c43be22"],"username":"Przemek"}’, ‘{"id":"638797306307ba909c43be22","email":"test3@test.com","password":"$2a$08$wvtwkdwzKg.ZbEvWb2L5desAwoX0gUj723V/WgqiRRRFGl4AEltrm","verify":1,"invitationsToMe":["6390a3b8cb716fa4d67d82d6"],"invitationsFromMe":[],"friendsList":["638777339b32b61a57e5ab4b","638776e89b32b61a57e5ab43","638889b46b30846785db55df","6389f4206f784a8e3d75cf10"],"username":"Maciek"}’, ‘{"id":"638777339b32b61a57e5ab4b","email":"test2@test.com","password":"$2a$08$Zl8eJP8B2yYJaFMdH5045uQZnKB8JMmOMmMfCQXN/C0UfN1eMWdAi","verify":1,"invitationsToMe":["6390a3b8cb716fa4d67d82d6"],"invitationsFromMe":[],"friendsList":["638797306307ba909c43be22","638776e89b32b61a57e5ab43","638889b46b30846785db55df","6389f4206f784a8e3d75cf10"],"username":"Bartolinio"}’ ] Now i want to extract from each "id" number to save in array in mondoDb. I found… Read More Get all strings from array in mongoDb