6

I am trying to add fields in a mongodb document using C# drivers.

I am creating a document.

BsonDocument document = new BsonDocument();

and adding

document.Add(name, value); // here name and value both are string

but I am not sure how to add an array in this scenario

like document.Add(name, values); // here values is List<string>

e.g. document.Add(skills, [C++, Java, C#]);

please help me with this

2
  • 1
    Did you read this page? Commented Feb 11, 2014 at 14:09
  • Yes, I have seen this page, but didn't got something direct ..... I am not sure if with some work around I can achieve this .... Commented Feb 12, 2014 at 5:35

1 Answer 1

7

If you're working with a List<string>:

var skills = new List<string> {"C++", "Java", "C#"};
document.Add("skills", new BsonArray(skills));

Or, more simply:

document.Add("skills", new BsonArray { "C++", "Java", "C#" } );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.