Answers for "Inserting documents to collections in database in MongoDB deployment"

0

Inserting documents to collections in database in MongoDB deployment

use mongodb::bson::{doc, Document};

// Get a handle to a collection in the database.
let collection = db.collection::<Document>("books");

let docs = vec![
    doc! { "title": "1984", "author": "George Orwell" },
    doc! { "title": "Animal Farm", "author": "George Orwell" },
    doc! { "title": "The Great Gatsby", "author": "F. Scott Fitzgerald" },
];

// Insert some documents into the "mydb.books" collection.
collection.insert_many(docs, None).await?;
Posted by: Guest on October-05-2021

Code answers related to "Inserting documents to collections in database in MongoDB deployment"

Browse Popular Code Answers by Language