[DOCS-9375] Comment on: "primer/client.txt" Created: 23/Nov/16  Updated: 01/Dec/16  Resolved: 01/Dec/16

Status: Closed
Project: Documentation
Component/s: primer
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Docs Collector User (Inactive) Assignee: Allison Reinheimer Moore
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Win 7 Enterprise, VS 2013

Location: https://docs.mongodb.com/getting-started/csharp/client/#csharp-download-connect
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Referrer: https://docs.mongodb.com/getting-started/csharp/insert/
Screen Resolution: 1536 x 864


Participants:
Days since reply: 7 years, 10 weeks, 6 days ago
Story Points: 0.25

 Description   

Hi, I'm supposed to use
"protected static IMongoClient _client;
protected static IMongoDatabase _database;

_client = new MongoClient();
_database = _client.GetDatabase("test");"

Upon rebuilding my code, I'm getting "Invalid expression term 'protected'. How do i resolve this?

my test code:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
 
namespace CSharpMongo
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Insert Data with C# Driver, https://docs.mongodb.com/getting-started/csharp/insert/
                #region Prerequisites
                    //Follow the Connect to MongoDB step to connect to a running MongoDB instance and declare and define the variable _database to access the test database.
                    //Include the 3 using statements (as shown per the site mentioned above).
                    #region Connect to MongoDB
                        //Add the 2 using statements in your C# program.
                        //Now, connect:
                        protected static IMongoClient _client;
                        protected static IMongoDatabase _database;
 
                        _client = new MongoClient();
                        _database = _client.GetDatabase("test");
                        //To specify a different host and port for the mongod instance, see the MongoClient API page
 
 
                    #endregion
 
                #endregion
            #endregion
        }
    }
}

Thanks in advance for your help,
Tien



 Comments   
Comment by Allison Reinheimer Moore [ 01/Dec/16 ]

Hi Tien Le,

Sorry for the delay on your MongoDB question about the C# driver [1]. Having talked with our engineers, protected static fields need to be declared in the class and not inside a method, which is why you're getting the error. You could alternatively use local variables.

If you have other questions with your code, the best place to ask them is probably the MongoDB User Google Group. If you find an issue specifically with the docs, do please file another Jira ticket!

Thanks so much!
Allison

Comment by Allison Reinheimer Moore [ 01/Dec/16 ]

To Allison for grooming.

Generated at Thu Feb 08 07:58:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.