Unknown discriminator value

199 views
Skip to first unread message

Asya Kamsky

unread,
May 6, 2013, 12:10:45 PM5/6/13
to mongod...@googlegroups.com
It's not clear to me where you are getting this error - are you sure this is from MongoDB? It helps to include the code or command you are running that is giving you problems.

Meanwhile in the shell the way you can get all distinct values of a field is with command:

> db.collection.distinct("fieldname")

Asya

scourmy soma

unread,
May 7, 2013, 1:40:46 AM5/7/13
to mongod...@googlegroups.com
Yes it is from mongodb.
I am working with the C# mongoDriver.
That the code:
var collection = new MongoClient(@"mongodb://localhost/MAM").GetServer()
.GetDatabase("MAM")
 .GetCollection<iLogEntry>("LogsCollection");
foreach (var item in collection.FindAll())
{
 
}
iLogEntry is a known Interface
in the collection there many types "_t" of documents saved
i am just interested in docs i saved by my own in this collection.
They are knwon classes in my program.
know theres are more discriminators in this collection as i know.
Little Example:
Save some Objects in a collection.
change the _t value of one of these objects.
try my code and you get the Exception i told.
i am not interested on this object.
i just want to find my own.
i could just search for my object with something like this
 collection.FindAs<X>(Query.EQ("_t"typeof(X).Name))
But with about 20 kinds of objects this doesnt look very good.

 
Am Montag, 6. Mai 2013 12:18:53 UTC+2 schrieb scourmy soma:
Hi there....
first of all i am  a newB working with mongodb.
i am trying to Find Documents in a Collection.
This Collection has many different Document Types.
Now there is the Fact that i just know some of those.

Example: in the collection there  are Docs with  the discriminators _t {'a','b','c','d'}
I just know 'a' and 'b'.
Now i just want to Find my known Types, but getting the Exeception "Unknown discriminator value",
How can i just read my known Types or prevent from getting the exception?
I hoped i desribed my problem,so you can understand it.


Thanks alot for reading or helping me...

Robert Stam

unread,
May 7, 2013, 11:02:25 AM5/7/13
to mongod...@googlegroups.com
If a collection contains many different kinds of documents and you only want to read some of them then you have to write a query that matches the documents you want to read. A query is the only available mechanism to filter which documents the server returns.

You could also use a LINQ query to filter by the document type:

var query = collection.AsQueryable<ILogEntry>().OfType<X>();

which results in the same query being sent to the server after the LINQ query has been translated to an equivalent MongoDB query.

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages