How to show created by "name" using mongodb?

Member

by lizzie , in category: MySQL , 5 months ago

How to show created by "name" using mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 5 months ago

@lizzie 

To show the documents in a MongoDB collection with a field indicating the creator's name, you can use the find() method with a query that includes the creator's name.


For example, if you have a collection called "documents" and each document has a field called "creator" containing the creator's name, you can retrieve all documents created by a specific user like this:

1
db.documents.find({ creator: "name" })


This query will return all documents in the "documents" collection where the "creator" field is equal to the specified name.


If you want to display the documents along with the creator's name, you can use the forEach() method to iterate over the results and print out the document and creator's name:

1
2
3
4
db.documents.find({ creator: "name" }).forEach(function(doc) {
    print("Document: ", doc);
    print("Creator: ", doc.creator);
})


This will print out each document created by the specified name along with the creator's name.

Related Threads:

How to hide and show divs on button click created dynamically in vue.js?
How to change color of donut chart created using d3.js?
How to add a background image to a plot created using d3.js?
How to check the server status in MongoDB using PHP?
How to select collection using it's name on shopify?
How to show a dropdown over a modal using tailwind css?