Deleting mongodb subdocument on certain date - node.js

I have a collection which stores document that can have multiple subdocument (e.g. a group collection with multiple votings). My goal is to delete certain subdocuments on a certain date. I thought about using a package like "agenda" to cron-like delete certain subdocuments. Are there any more efficient or easier ways to do that

Related

What can be an alternative to mongoose populate in native mongodb driver where my query may return multiple documents

What can be an alternative to mongoose populate for mongodb driver where my query may return multiple documents and each document can have multiple children(max 5-6) stored in different collection. I want each document populated with children props.
fx.
a user has multiple orders and each order has many items(each order only stores the id of an item). Now I've a query to get orders between specific time period and that will reurn multiple orders and now i want these orders to be populated with item(fx item price, item size)
one potential solution could be get all orders and make 5-6(no. of items) additional query, which i assume to be a performance bottleneck
*Nodejs mongo driver

Is there any way to find distinct documents in mongo using nodejs

I actually want To display Full documents Without duplication
When I use distinct i can only display one particular field
How to display all fields without selecting that document which is repeated
Each document in MongoDB contains an _id field which must be unique in the collection. Hence, it is not possible to have two identical documents in a collection. Ergo, iterating a collection with no conditions will return all unique documents (which are all documents in the collection).

is it possible to update collection name dynamically in cloud firestore?

I am trying to create a collection name based on the date like i have a collection name like this Change 06-05-2020 and i want to overwrite this collection daily and make the collection name like this Change 07-05-2020 and so on is it possible to do it i ma creating the collection in this way.and basically i am trying to store the daily updated data in a particular way so i can track that information.so can i update the collection name dynamically daily?
await growthfilemsdb.collection(`Change${getISO8601Date()}`).doc(change.after.data().officeId).set(change.after.data(),{merge:false})
It's not possible to change the name of a collection. What you can do instead is simply copy all the documents from the old collection to a new one with a new name.
However, it's usually not a good idea to make the names of your collection dynamic like this. Instead, consider putting the date as a field inside the document, and using that to filter the results of queries or delete old documents.

How to $pull ObjectId from multiple collections simultaneously?

For a dating site I have a db of hundreds of different Users.
Fields such as "matches", "heartedMe" contain the ObjectId of different users in Array form.
When I delete a user I need to search every collection and delete any references to the deleted user by $pull ing their ObjectId from all relevant fields.
Any thoughts on the sort of query I would need to run? Currently I've just found All Users!
Thanks a lot!

Deleting queried documents from Azure's CosmosDB

I have a collection in CosmosDB that has a large number of JSON files. I have a python program that continuously writes and uploads data to that collection. My format of the data just changed, so I am now writing files with a new structure. I have to delete all the files in my collection with the old structure.
Question 1: Do the documents have a date of creation tag? If so, I would like to delete all the files that have a date of creation earlier than a specific date. How can I do that?
Question 2: If the answer to the previous question is no, there is a way I can query parts inside all the old files I want to delete. I cannot query the files entirely, but I can query what's inside of them. So is there a way to delete the entire documents based on the query of what's inside of them? Maybe if there is a way to retrieve all the document IDs that are used to respond to my query, then it would be possible.
All documents have a property called _ts which is the unix timestamp of when the document was created and is auto populated by Cosmos. You should be able to query using this property to find all the documents created before a specific date.

Resources