Himani Talesara
Himani Talesara

Reputation: 305

Inserting array of values in a document

A mongo document can have a key with multiple values. For eg. Phone no can have several values. I want to insert this array with the help of c# driver API. Please tellme the way to insert such values. Thanks.

Upvotes: 0

Views: 146

Answers (1)

Craig Wilson
Craig Wilson

Reputation: 12624

You can do this pretty easily.

BsonDocument doc = new BsonDocument();
BsonArray phones = new BsonArray();
phones.Add("123-456-7890");
phones.Add("234-567-8901");
doc.Add("phones", phones);

collection.Insert(doc);

If this isn't what you are looking for, please let us know.

Upvotes: 2

Related Questions