[CSHARP-757] Overriding Collection Name in MongoDb Created: 11/Jun/13 Updated: 05/Apr/19 Resolved: 11/Jun/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.8.1 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | joseph rodriguez | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 2008, Windows 7 |
||
| Description |
|
I have a .Net object named CacheItem<T> that gets persisted to MongoDb. When the object gets persisted, the name of the collection becomes CacheItem`1. If I try to use and shell commands against that document I get 'javascript illegal' error message due to the name that contains the tick mark, '`'. Is there a way to set the name of the object so that it isnt named as such? |
| Comments |
| Comment by Craig Wilson [ 11/Jun/13 ] | ||
|
Joseph, Hope that helps. I'm going to close this ticket as works as designed. Feel free to post back if you need some more help or clarification. Thanks, | ||
| Comment by joseph rodriguez [ 11/Jun/13 ] | ||
|
Here is my save method: public void Add<T>(string key, T item, int expiryMinutes = 0) ; collection.Save(cacheItem); public MongoCollection<T> GetDocumentCollection<T>() { return Database.GetCollection<T>(typeof(T).Name); }So my helper method is using the name of the object. Since the object is of generic type, that is where that name with the tick mark is coming from. I should provide an override to explicitly state the name of the object in this case. Thanks | ||
| Comment by Robert Stam [ 11/Jun/13 ] | ||
|
The driver does not set the name of the collection. The application code sets the name of the collection, using code something like this:
Can you provide some sample code where you are calling GetCollection? |