java - Spring MongoDB Criteria update -


how can write query update "contacts.collection.value._class = subclass2" , set value xyz spring mongodb criteria?

{ "_class" : "myclass",   "_id" : objectid( "51ecc95503644e4489bb742e" ),   "contacts" : [      { "property1" : "value1",       "property2" : "value2",       "collection" : [          { "value" : "1",           "_class" : "subclass1" },          { "value" : "2",           "_class" : "subclass2" },          { "value" : "2",           "_class" : "subclass3" },  

i trying spring data mongo criteria class.

so far got it's not working

            query = new query(criteria.where("_id").is(myclassid)                     .and("contacts.collection.value").is("2")                     .and("contacts.collection._class").is("subclass2"));             update.set("contacts.collection.$.value", "3");             mongotemplate.updatefirst(query, update, myclass.class); 

i'm getting error;

java.lang.illegalargumentexception: no property value found on ...!

notes:

  1. the "contacts" collection list of interface.
  2. i sanitized variable names , class names.
  3. if don't know how criteria, please give me java code.

thanks

adding stacktrace

here stack trace

java.lang.illegalargumentexception: no property xyz found on com.blah.someinterface!         @ org.springframework.data.mapping.context.abstractmappingcontext.getpersistentpropertypath(abstractmappingcontext.java:225) ~[spring-data-commons-1.5.1.release.jar:na]         @ org.springframework.data.mongodb.core.convert.querymapper.getpath(querymapper.java:202) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.convert.querymapper.gettargetproperty(querymapper.java:190) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.convert.querymapper.getmappedobject(querymapper.java:86) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.mongotemplate$11.doincollection(mongotemplate.java:925) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.mongotemplate$11.doincollection(mongotemplate.java:920) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.mongotemplate.execute(mongotemplate.java:388) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.mongotemplate.doupdate(mongotemplate.java:920) ~[spring-data-mongodb-1.2.1.release.jar:na]         @ org.springframework.data.mongodb.core.mongotemplate.updatefirst(mongotemplate.java:902) ~[spring-data-mongodb-1.2.1.release.jar:na] 

based on jayz's answer, wrote update robomongo , works updates query result!

db.mydb.update( { "_id":objectid("51ecc95503644e4489bb742e"), "contacts.collection._class": "subclass1", "contacts.collection.value": "1", }, {      $set: { 'contacts.0.collection.$.value': '3' }  }, { getlasterror: 1 }); 

but when try mongotemplate nothing updated.

query index of collection array matches query criteria. data structure, need 2 array indexes, 1 contacts , 1 collection, not possible (as far know). need know position of either contacts array item or collection array item. let's assume know position of contacts array item. if 0th position, here complete query:

query = new query(new criteria().andoperator(         criteria.where("_id").is(myclassid),         criteria.where("contacts.collection.value").is("2"),         criteria.where("contacts.collection._class").is("subclass2"));         update.set("contacts.0.collection.$.value", "3");         mongotemplate.updatefirst(query, update, myclass.class); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -