Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MongoDB.Driver;
- using MongoDB.Bson;
- namespace MongoDB_Test
- {
- class Program
- {
- private static IMongoClient client;
- private static IMongoDatabase database;
- protected static IMongoClient Client
- {
- get
- {
- return client;
- }
- set
- {
- client = value;
- }
- }
- protected static IMongoDatabase Database
- {
- get
- {
- return database;
- }
- set
- {
- database = value;
- }
- }
- static void Main(string[] args)
- {
- Client = new MongoClient();
- Database = Client.GetDatabase("test");
- doJob();
- }
- static void doJob()
- {
- var document = new BsonDocument
- {
- { "address" , new BsonDocument
- {
- { "street", "2 Avenue" },
- { "zipcode", "10075" },
- { "building", "1480" },
- { "coord", new BsonArray { 73.9557413, 40.7720266 } }
- }
- },
- { "borough", "Manhattan" },
- { "cuisine", "Italian" },
- { "grades", new BsonArray
- {
- new BsonDocument
- {
- { "date", new DateTime(2014, 10, 1, 0, 0, 0, DateTimeKind.Utc) },
- { "grade", "A" },
- { "score", 11 }
- },
- new BsonDocument
- {
- { "date", new DateTime(2014, 1, 6, 0, 0, 0, DateTimeKind.Utc) },
- { "grade", "B" },
- { "score", 17 }
- }
- }
- },
- { "name", "Vella" },
- { "restaurant_id", "41704620" }
- };
- var collection = Database.GetCollection<BsonDocument>("restaurants");
- try
- {
- collection.InsertOne(document);
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement