문서 메뉴
문서 홈
/
MongoDB 매뉴얼
/

문서 삽입

이 페이지의 내용

  • MongoDB Atlas UI에 문서 삽입
  • 단일 문서 삽입
  • 여러 문서를 삽입합니다.
  • 동작 삽입

오른쪽 상단의 언어 선택 드롭다운 메뉴를 사용하여 다음 예제의 언어를 설정하거나 MongoDB Compass를 선택합니다.


이 페이지에서는 MongoDB 삽입 작업의 예시를 제공합니다.

다음 메서드를 사용하여 MongoDB에서 문서를 쿼리할 수 있습니다.

  • 프로그래밍 언어의 드라이버입니다.

  • MongoDB Atlas UI. 자세한 내용 은 MongoDB Atlas UI에 문서 삽입 을 참조하세요.

  • MongoDB Compass

참고

컬렉션 만들기

컬렉션이 현재 존재하지 않는 경우 삽입 작업을 수행하면 컬렉션이 생성됩니다.

MongoDB Atlas UI에 문서를 삽입하려면 다음 단계를 완료하세요. MongoDB Atlas UI에서 문서 작업을 수행하는 방법을 자세히 알아보려면 문서 생성, 보기, 업데이트 및 삭제를 참조하세요.

1
  1. MongoDB Atlas UI의 Database 사이드바에서 버튼을 클릭합니다.

  2. 문서를 추가하려는 데이터베이스 배포에 대해 Browse Collections를 클릭합니다.

  3. 왼쪽 탐색 창에서 데이터베이스를 선택합니다.

  4. 왼쪽 탐색 창에서 컬렉션을 선택합니다.

2
  1. Insert Document를 클릭합니다.

  2. {} 아이콘을 클릭하면 JSON 보기가 나타납니다.

  3. 문서 배열을 텍스트 입력 필드에 붙여넣습니다. 예를 들어, 다음 항목은 각각 3개의 필드를 포함하는 4개의 문서를 생성합니다.

    [
    { "prodId": 100, "price": 20, "quantity": 125 },
    { "prodId": 101, "price": 10, "quantity": 234 },
    { "prodId": 102, "price": 15, "quantity": 432 },
    { "prodId": 103, "price": 17, "quantity": 320 }
    ]
3

MongoDB Atlas가 컬렉션에 문서를 추가합니다.

db.collection.insertOne()단일 문서 를 컬렉션에 삽입합니다.

다음은 inventory 컬렉션에 새 문서를 삽입하는 예시입니다. 문서에서 _id 필드를 지정하지 않으면 MongoDB는 _id ObjectId 값이 있는 필드를 새 문서에 추가합니다. 자세한 내용은 삽입 동작을 참조하세요.

MongoDB Compass를 사용하여 단일 문서를 삽입하려면 다음을 수행합니다.

  1. 문서를 삽입하려는 컬렉션으로 이동합니다.

    1. 왼쪽 MongoDB Compass 탐색 창에서 대상 컬렉션이 속한 데이터베이스를 클릭합니다.

    2. 데이터베이스 뷰에서 대상 컬렉션 이름을 클릭합니다.

  2. Insert Document 버튼을 클릭합니다.

    Compass 삽입 버튼
  3. 문서의 각 필드에 대해 필드 유형을 선택하고 필드 이름과 값을 입력합니다. 마지막 줄 번호를 클릭하고 다음을 클릭하여 필드를 추가합니다. Add Field After ...

    • Object 유형의 경우 마지막 필드의 번호를 클릭하고 Add Field After ...을(를) 선택하여 중첩된 필드를 추가합니다.

    • Array 유형의 경우 마지막 요소의 줄 번호를 클릭하고 Add Array Element After ...를 선택하여 배열에 요소를 추가합니다.

  4. 모든 필드를 입력한 후 Insert 을(를) 클릭합니다.

다음 예에서는 test.inventory 컬렉션에 새 문서를 삽입합니다.

IMongoCollection.InsertOne() 단일 문서 를 컬렉션에 삽입합니다.

다음은 inventory 컬렉션에 새 문서를 삽입하는 예시입니다. 문서가 _id 필드를 지정하지 않으면 C# 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

Collection.InsertOne 단일 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

com.mongodb.reactivestreams.client.MongoCollection.insertOne Java Reactive Streams 드라이버 를 사용하여 컬렉션에 단일 문서 를 삽입합니다. :

{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }

다음 예시에서는 위의 문서를 inventory 컬렉션에 삽입합니다. 문서가 _id 필드를 지정하지 않으면 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

com.mongodb.client.MongoCollection.insertOne 단일 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

단일 motor.motor_asyncio.AsyncIOMotorCollection.insert_one 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 모터 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

Collection.insertOne() 단일 문서 를 컬렉션에 삽입합니다.

다음은 inventory 컬렉션에 새 문서를 삽입하는 예시입니다. 문서가 _id 필드를 지정하지 않으면 Node.js 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 자세한 내용은 삽입 동작을 참조하세요.

MongoDB::Collection::insert_one() 단일 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 펄(Perl) 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

MongoDB\\Collection::insertOne()은(는) 단일 문서를 컬렉션에 삽입합니다.

다음은 inventory 컬렉션에 새 문서를 삽입하는 예시입니다. 문서에서 _id 필드를 지정하지 않은 경우 PHP 드라이버는 ObjectID 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

단일 pymongo.collection.Collection.insert_one 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 PyMongo 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

Mongo::Collection#insert_one()단일 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 Ruby 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

collection.insertOne() 단일 문서 를 컬렉션에 삽입합니다.

다음 예시에서는 inventory 컬렉션에 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 스칼라 드라이버는 ObjectId 값이 있는 _id 필드를 새 문서에 추가합니다. 삽입 동작을 참조하세요.

db.inventory.insertOne(
{ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } }
)
Compass 컬렉션에 새 문서 삽입
var document = new BsonDocument
{
{ "item", "canvas" },
{ "qty", 100 },
{ "tags", new BsonArray { "cotton" } },
{ "size", new BsonDocument { { "h", 28 }, { "w", 35.5 }, { "uom", "cm" } } }
};
collection.InsertOne(document);
result, err := coll.InsertOne(
context.TODO(),
bson.D{
{"item", "canvas"},
{"qty", 100},
{"tags", bson.A{"cotton"}},
{"size", bson.D{
{"h", 28},
{"w", 35.5},
{"uom", "cm"},
}},
})
Document canvas = new Document("item", "canvas")
.append("qty", 100)
.append("tags", singletonList("cotton"));
Document size = new Document("h", 28)
.append("w", 35.5)
.append("uom", "cm");
canvas.put("size", size);
Publisher<Success> insertOnePublisher = collection.insertOne(canvas);
Document canvas = new Document("item", "canvas")
.append("qty", 100)
.append("tags", singletonList("cotton"));
Document size = new Document("h", 28)
.append("w", 35.5)
.append("uom", "cm");
canvas.put("size", size);
collection.insertOne(canvas);
await db.inventory.insert_one(
{
"item": "canvas",
"qty": 100,
"tags": ["cotton"],
"size": {"h": 28, "w": 35.5, "uom": "cm"},
}
)
await db.collection('inventory').insertOne({
item: 'canvas',
qty: 100,
tags: ['cotton'],
size: { h: 28, w: 35.5, uom: 'cm' }
});
$db->coll("inventory")->insert_one(
{
item => "canvas",
qty => 100,
tags => ["cotton"],
size => { h => 28, w => 35.5, uom => "cm" }
}
);
$insertOneResult = $db->inventory->insertOne([
'item' => 'canvas',
'qty' => 100,
'tags' => ['cotton'],
'size' => ['h' => 28, 'w' => 35.5, 'uom' => 'cm'],
]);
db.inventory.insert_one(
{
"item": "canvas",
"qty": 100,
"tags": ["cotton"],
"size": {"h": 28, "w": 35.5, "uom": "cm"},
}
)
client[:inventory].insert_one({ item: 'canvas',
qty: 100,
tags: [ 'cotton' ],
size: { h: 28, w: 35.5, uom: 'cm' } })
collection.insertOne(
Document("item" -> "canvas", "qty" -> 100, "tags" -> Seq("cotton"), "size" -> Document("h" -> 28, "w" -> 35.5, "uom" -> "cm"))
).execute()

insertOne()는 새로 삽입된 문서의 _id 필드 값이 포함된 문서를 반환합니다. 반환 문서의 예는 db.collection.insertOne() 레퍼런스를 참고하세요.

참고

MongoDB Compass는 _id 필드와 해당 값을 자동으로 생성합니다. 생성된 ObjectId 는 무작위로 생성된 고유한 16진수 값으로 구성됩니다.

고유한 상태로 유지되고 유효한 ObjectId 인 한 문서를 삽입하기 전에 이 값을 변경할 수 있습니다. _id 필드에 대한 자세한 내용은 _id 필드를 참조하세요.

Collection.InsertOne 함수는 InsertedID 속성에 새로 삽입된 문서의 _id이(가) 포함된 InsertOneResult의 인스턴스를 반환합니다.

com.mongodb.client.MongoCollection.insertOne InsertOneResult 인스턴스를 반환합니다. . getInsertedId() 를 호출하여 _id 삽입된 문서의 필드에 액세스할 수 있습니다. 메서드를 호출합니다.

insert_one pymongo.results.InsertOneResult inserted_id_id 인스턴스를 반환합니다. 필드에는 새로 삽입된 문서의 이 포함되어 있습니다.

insertOne()result을(를) 제공하는 프로미스를 반환합니다. result.insertedId 프로미스에는 새로 삽입된 문서의 _id이(가) 포함되어 있습니다.

삽입에 성공하면 insert_one() 메서드는 MongoDB::InsertOneResult 인스턴스를 inserted_id _id 반환합니다. 속성에 새로 삽입된 문서의 가 포함되어 있습니다.

삽입에 성공하면 insertOne() 메서드는 getInsertedId() 메서드가 새로 삽입된 문서의 _id을(를) 반환하는 MongoDB\\InsertOneResult의 인스턴스를 반환합니다.

insert_one pymongo.results.InsertOneResult inserted_id_id 인스턴스를 반환합니다. 필드에는 새로 삽입된 문서의 이 포함되어 있습니다.

삽입에 성공하면 insert_one() 메서드는 inserted_id 속성에 새로 삽입된 문서의 _id이(가) 포함된 Mongo::Operation::Result의 인스턴스를 반환합니다.

삽입에 성공하면, collection.insertOne() 메서드는 collection.insertOne().results();의 인스턴스를 반환합니다. inserted_id 속성에는 새로 삽입된 문서의 _id 가 포함되어 있습니다.

방금 삽입한 문서를 조회하려면 컬렉션을 쿼리합니다.

db.inventory.find( { item: "canvas" } )
컬렉션에서 일치하는 문서 쿼리

MongoDB Compass 쿼리 표시줄에서 필터를 지정하고 Find 을 클릭하여 쿼리를 실행합니다.

위의 필터는 MongoDB Compass가 item 필드가 canvas 인 문서만 반환하도록 지정합니다.

MongoDB Compass 쿼리 바에 대한 자세한 내용은 Compass 쿼리 바 설명서를 참조하세요.

var filter = Builders<BsonDocument>.Filter.Eq("item", "canvas");
var result = collection.Find(filter).ToList();
cursor, err := coll.Find(
context.TODO(),
bson.D{{"item", "canvas"}},
)
FindPublisher<Document> findPublisher = collection.find(eq("item", "canvas"));
FindIterable<Document> findIterable = collection.find(eq("item", "canvas"));
cursor = db.inventory.find({"item": "canvas"})
const cursor = db.collection('inventory').find({ item: 'canvas' });
$cursor = $db->coll("inventory")->find( { item => "canvas" } );
$cursor = $db->inventory->find(['item' => 'canvas']);
cursor = db.inventory.find({"item": "canvas"})
client[:inventory].find(item: 'canvas')
val observable = collection.find(equal("item", "canvas"))

➤ 오른쪽 상단의 언어 선택 드롭다운 메뉴를 사용하여 이 페이지에 있는 예제의 언어를 설정하세요.


버전 3.2에 새로 추가되었습니다.

db.collection.insertMany()는 컬렉션에 여러 문서를 삽입할 수 있습니다. 메서드에 문서 배열을 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 MongoDB는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

IMONGOCollection.InsertMany()는 컬렉션에 여러 문서를 삽입할 수 있습니다. 열거 가능한 문서 컬렉션을 메서드에 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

Collection.InsertMany 컬렉션에 여러 문서 를 삽입할 수 있습니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

com.mongodb.reactivestreams.client.MongoCollection.html.insertMany Java Reactive Streams 드라이버 를 사용하여 다음 문서를 삽입합니다. :

{ item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom: "cm" } }
{ item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } }
{ item: "mousepad", qty: 25, tags: ["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } }

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

com.mongodb.client.MongoCollection.insertMany 컬렉션에 여러 문서 를 삽입할 수 있습니다. 메서드에 문서 목록을 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

motor.motor_asyncio.AsyncIOMotorCollection.insert_many은(는) 컬렉션에 여러 문서를 삽입할 수 있습니다. 메서드에 반복 가능한 문서를 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 PyMongo 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

Collection.insertMany() 컬렉션에 여러 문서 를 삽입할 수 있습니다. 메서드에 문서 배열을 전달합니다.

다음 예시에서는 inventory 컬렉션에 3개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 Node.js 드라이버는 ObjectId 값과 함께 _id 필드를 각 문서에 추가합니다. 자세한 내용은 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

MongoDB::Collection::insert_many() 컬렉션에 여러 문서 를 삽입할 수 있습니다. 문서의 배열 참조를 메서드에 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 펄(Perl) 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

MongoDB\\Collection::insertMany()은(는) 컬렉션에 여러 문서를 삽입할 수 있습니다. 메서드에 문서 배열을 전달합니다.

다음 예시에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우 PHP 드라이버는 ObjectId 값과 함께 _id 필드를 각 문서에 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

pymongo.collection.Collection.insert_many은(는) 컬렉션에 여러 문서를 삽입할 수 있습니다. 메서드에 반복 가능한 문서를 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 PyMongo 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

Mongo::Collection#insert_many() 는 컬렉션에 여러 문서 를 삽입할 수 있습니다. 메서드에 문서 배열을 전달합니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서에 _id 필드가 지정되지 않은 경우, Ruby 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

버전 3.2에 새로 추가되었습니다.

collection.insertMany() 컬렉션에 여러 문서 를 삽입할 수 있습니다.

다음 예에서는 inventory 컬렉션에 세 개의 새 문서를 삽입합니다. 문서가 _id 필드를 지정하지 않으면 스칼라 드라이버는 각 문서에 ObjectId 값이 있는 _id 필드를 추가합니다. 삽입 동작을 참조하세요.

db.inventory.insertMany([
{ item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom: "cm" } },
{ item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } },
{ item: "mousepad", qty: 25, tags: ["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } }
])
[
{ "item": "canvas", "qty": 100, "size": { "h": 28, "w": 35.5, "uom": "cm" }, "status": "A" },
{ "item": "journal", "qty": 25, "size": { "h": 14, "w": 21, "uom": "cm" }, "status": "A" },
{ "item": "mat", "qty": 85, "size": { "h": 27.9, "w": 35.5, "uom": "cm" }, "status": "A" },
{ "item": "mousepad", "qty": 25, "size": { "h": 19, "w": 22.85, "uom": "cm" }, "status": "P" },
{ "item": "notebook", "qty": 50, "size": { "h": 8.5, "w": 11, "uom": "in" }, "status": "P" },
{ "item": "paper", "qty": 100, "size": { "h": 8.5, "w": 11, "uom": "in" }, "status": "D" },
{ "item": "planner", "qty": 75, "size": { "h": 22.85, "w": 30, "uom": "cm" }, "status": "D" },
{ "item": "postcard", "qty": 45, "size": { "h": 10, "w": 15.25, "uom": "cm" }, "status": "A" },
{ "item": "sketchbook", "qty": 80, "size": { "h": 14, "w": 21, "uom": "cm" }, "status": "A" },
{ "item": "sketch pad", "qty": 95, "size": { "h": 22.85, "w": 30.5, "uom": "cm" }, "status": "A" }
]

MongoDB Compass를 사용하여 문서를 삽입하는 방법에 대한 지침은 문서 삽입을 참조하세요.

var documents = new BsonDocument[]
{
new BsonDocument
{
{ "item", "journal" },
{ "qty", 25 },
{ "tags", new BsonArray { "blank", "red" } },
{ "size", new BsonDocument { { "h", 14 }, { "w", 21 }, { "uom", "cm"} } }
},
new BsonDocument
{
{ "item", "mat" },
{ "qty", 85 },
{ "tags", new BsonArray { "gray" } },
{ "size", new BsonDocument { { "h", 27.9 }, { "w", 35.5 }, { "uom", "cm"} } }
},
new BsonDocument
{
{ "item", "mousepad" },
{ "qty", 25 },
{ "tags", new BsonArray { "gel", "blue" } },
{ "size", new BsonDocument { { "h", 19 }, { "w", 22.85 }, { "uom", "cm"} } }
},
};
collection.InsertMany(documents);
result, err := coll.InsertMany(
context.TODO(),
[]interface{}{
bson.D{
{"item", "journal"},
{"qty", int32(25)},
{"tags", bson.A{"blank", "red"}},
{"size", bson.D{
{"h", 14},
{"w", 21},
{"uom", "cm"},
}},
},
bson.D{
{"item", "mat"},
{"qty", int32(25)},
{"tags", bson.A{"gray"}},
{"size", bson.D{
{"h", 27.9},
{"w", 35.5},
{"uom", "cm"},
}},
},
bson.D{
{"item", "mousepad"},
{"qty", 25},
{"tags", bson.A{"gel", "blue"}},
{"size", bson.D{
{"h", 19},
{"w", 22.85},
{"uom", "cm"},
}},
},
})
Document journal = new Document("item", "journal")
.append("qty", 25)
.append("tags", asList("blank", "red"));
Document journalSize = new Document("h", 14)
.append("w", 21)
.append("uom", "cm");
journal.put("size", journalSize);
Document mat = new Document("item", "mat")
.append("qty", 85)
.append("tags", singletonList("gray"));
Document matSize = new Document("h", 27.9)
.append("w", 35.5)
.append("uom", "cm");
mat.put("size", matSize);
Document mousePad = new Document("item", "mousePad")
.append("qty", 25)
.append("tags", asList("gel", "blue"));
Document mousePadSize = new Document("h", 19)
.append("w", 22.85)
.append("uom", "cm");
mousePad.put("size", mousePadSize);
Publisher<Success> insertManyPublisher = collection.insertMany(asList(journal, mat, mousePad));
Document journal = new Document("item", "journal")
.append("qty", 25)
.append("tags", asList("blank", "red"));
Document journalSize = new Document("h", 14)
.append("w", 21)
.append("uom", "cm");
journal.put("size", journalSize);
Document mat = new Document("item", "mat")
.append("qty", 85)
.append("tags", singletonList("gray"));
Document matSize = new Document("h", 27.9)
.append("w", 35.5)
.append("uom", "cm");
mat.put("size", matSize);
Document mousePad = new Document("item", "mousePad")
.append("qty", 25)
.append("tags", asList("gel", "blue"));
Document mousePadSize = new Document("h", 19)
.append("w", 22.85)
.append("uom", "cm");
mousePad.put("size", mousePadSize);
collection.insertMany(asList(journal, mat, mousePad));
await db.inventory.insert_many(
[
{
"item": "journal",
"qty": 25,
"tags": ["blank", "red"],
"size": {"h": 14, "w": 21, "uom": "cm"},
},
{
"item": "mat",
"qty": 85,
"tags": ["gray"],
"size": {"h": 27.9, "w": 35.5, "uom": "cm"},
},
{
"item": "mousepad",
"qty": 25,
"tags": ["gel", "blue"],
"size": {"h": 19, "w": 22.85, "uom": "cm"},
},
]
)
await db.collection('inventory').insertMany([
{
item: 'journal',
qty: 25,
tags: ['blank', 'red'],
size: { h: 14, w: 21, uom: 'cm' }
},
{
item: 'mat',
qty: 85,
tags: ['gray'],
size: { h: 27.9, w: 35.5, uom: 'cm' }
},
{
item: 'mousepad',
qty: 25,
tags: ['gel', 'blue'],
size: { h: 19, w: 22.85, uom: 'cm' }
}
]);
$db->coll("inventory")->insert_many(
[
{
item => "journal",
qty => 25,
tags => [ "blank", "red" ],
size => { h => 14, w => 21, uom => "cm" }
},
{
item => "mat",
qty => 85,
tags => ["gray"],
size => { h => 27.9, w => 35.5, uom => "cm" }
},
{
item => "mousepad",
qty => 25,
tags => [ "gel", "blue" ],
size => { h => 19, w => 22.85, uom => "cm" }
}
]
);
$insertManyResult = $db->inventory->insertMany([
[
'item' => 'journal',
'qty' => 25,
'tags' => ['blank', 'red'],
'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
],
[
'item' => 'mat',
'qty' => 85,
'tags' => ['gray'],
'size' => ['h' => 27.9, 'w' => 35.5, 'uom' => 'cm'],
],
[
'item' => 'mousepad',
'qty' => 25,
'tags' => ['gel', 'blue'],
'size' => ['h' => 19, 'w' => 22.85, 'uom' => 'cm'],
],
]);
db.inventory.insert_many(
[
{
"item": "journal",
"qty": 25,
"tags": ["blank", "red"],
"size": {"h": 14, "w": 21, "uom": "cm"},
},
{
"item": "mat",
"qty": 85,
"tags": ["gray"],
"size": {"h": 27.9, "w": 35.5, "uom": "cm"},
},
{
"item": "mousepad",
"qty": 25,
"tags": ["gel", "blue"],
"size": {"h": 19, "w": 22.85, "uom": "cm"},
},
]
)
client[:inventory].insert_many([{ item: 'journal',
qty: 25,
tags: ['blank', 'red'],
size: { h: 14, w: 21, uom: 'cm' }
},
{ item: 'mat',
qty: 85,
tags: ['gray'],
size: { h: 27.9, w: 35.5, uom: 'cm' }
},
{ item: 'mousepad',
qty: 25,
tags: ['gel', 'blue'],
size: { h: 19, w: 22.85, uom: 'cm' }
}
])
collection.insertMany(Seq(
Document("item" -> "journal", "qty" -> 25, "tags" -> Seq("blank", "red"), "size" -> Document("h" -> 14, "w" -> 21, "uom" -> "cm")),
Document("item" -> "mat", "qty" -> 85, "tags" -> Seq("gray"), "size" -> Document("h" -> 27.9, "w" -> 35.5, "uom" -> "cm")),
Document("item" -> "mousepad", "qty" -> 25, "tags" -> Seq("gel", "blue"), "size" -> Document("h" -> 19, "w" -> 22.85, "uom" -> "cm"))
)).execute()

insertMany()는 새로 삽입된 문서의 _id 필드 값을 포함하는 문서를 반환합니다. 예제를 보려면 레퍼런스를 참조하세요.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입된 문서를 검색하려면 collection을 쿼리합니다:

com.mongodb.reactivestreams.client.MongoCollection.html.insertMany 게시자 를 반환합니다.객체. 는 Publisher 구독자가 데이터를 요청할 때 컬렉션에 문서를 삽입합니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입된 문서를 검색하려면 collection을 쿼리합니다:

insert_many pymongo.results.InsertManyResult inserted_ids_id 인스턴스를 반환합니다. 필드는 새로 삽입된 각 문서의 을 포함하는 목록입니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

insertMany()result을(를) 제공하는 프로미스를 반환합니다. result.insertedIds 필드에는 새로 삽입된 각 문서의 _id이(가) 포함된 배열이 포함되어 있습니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입에 성공하면 insert_many() 메서드는 inserted_ids 속성이 새로 삽입된 각 문서의 _id을(를) 포함하는 목록인 MongoDB::InsertManyResult의 인스턴스를 반환합니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입에 성공하면 insertMany() 메서드는 getInsertedIds() 메서드가 새로 삽입된 각 문서의 _id을(를) 반환하는 MongoDB\\InsertManyResult의 인스턴스를 반환합니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

insert_many pymongo.results.InsertManyResult inserted_ids_id 인스턴스를 반환합니다. 필드는 새로 삽입된 각 문서의 을 포함하는 목록입니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입에 성공하면 insert_many() 메서드는 inserted_ids 속성이 새로 삽입된 각 문서의 _id을(를) 포함하는 목록인 Mongo::BulkWrite::Result의 인스턴스를 반환합니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

삽입에 성공하면 insertMany() 메서드는 작업이 완료된 시기를 나타내는 유형 매개변수 또는 com.mongodb.DuplicateKeyException 또는 com.mongodb.MongoException와(과) 함께 Observable을 반환합니다.

삽입된 문서를 검색하려면 collection을 쿼리합니다:

db.inventory.find( {} )
Compass 컬렉션의 모든 문서 선택
var filter = Builders<BsonDocument>.Filter.Empty;
var result = collection.Find(filter).ToList();
cursor, err := coll.Find(
context.TODO(),
bson.D{},
)
FindPublisher<Document> findPublisher = collection.find(new Document());
FindIterable<Document> findIterable = collection.find(new Document());
cursor = db.inventory.find({})
const cursor = db.collection('inventory').find({});
$cursor = $db->coll("inventory")->find( {} );
$cursor = $db->inventory->find([]);
cursor = db.inventory.find({})
client[:inventory].find({})
var findObservable = collection.find(Document())

컬렉션이 현재 존재하지 않는 경우 삽입 작업을 수행하면 컬렉션이 생성됩니다.

MongoDB에서 collection에 저장된 각 문서에는 기본 키 역할을 하는 고유한 _id 필드가 필요합니다. 삽입된 문서에서 _id 필드가 생략된 경우, MongoDB 드라이버는 _id 필드에 대한 객체 ID를 자동으로 생성합니다.

이는 upsert: true를 사용하여 업데이트 작업을 통해 삽입된 문서에도 적용됩니다.

MongoDB의 모든 쓰기 연산은 단일 문서 수준에서 원자적으로 이루어집니다. MongoDB 및 원자성에 대한 자세한 내용은 원자성 및 트랜잭션을 참조하세요.

쓰기 고려를 사용하여 MongoDB에서 쓰기 작업에 요청한 승인 수준을 지정할 수 있습니다. 자세한 내용은 쓰기 고려 항목에서 확인 가능합니다.

다음도 참조하세요.

돌아가기

CRUD 작업

다음

방법