{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/morphia/issues/933","repository_url":"https://api.github.com/repos/mongodb/morphia","labels_url":"https://api.github.com/repos/mongodb/morphia/issues/933/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/morphia/issues/933/comments","events_url":"https://api.github.com/repos/mongodb/morphia/issues/933/events","html_url":"https://github.com/mongodb/morphia/issues/933","id":154255832,"number":933,"title":"Documentation of query building is incomplete: Criteria needed for *and* and similar operators","user":{"login":"BairDev","id":2767014,"avatar_url":"https://avatars.githubusercontent.com/u/2767014?v=3","gravatar_id":"","url":"https://api.github.com/users/BairDev","html_url":"https://github.com/BairDev","followers_url":"https://api.github.com/users/BairDev/followers","following_url":"https://api.github.com/users/BairDev/following{/other_user}","gists_url":"https://api.github.com/users/BairDev/gists{/gist_id}","starred_url":"https://api.github.com/users/BairDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BairDev/subscriptions","organizations_url":"https://api.github.com/users/BairDev/orgs","repos_url":"https://api.github.com/users/BairDev/repos","events_url":"https://api.github.com/users/BairDev/events{/privacy}","received_events_url":"https://api.github.com/users/BairDev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-11T14:20:58Z","updated_at":"2016-05-11T17:44:41Z","closed_at":null,"body":"* Morphia Version. 1.1.1\r\n* JDK: 1.8\r\n* Mongo: 3.0.x\r\n\r\nThe current [documentation of complex queries](http://mongodb.github.io/morphia/1.1/guides/querying/#complex-queries:50d269286defa89dcc6793dab2a5c4d0) is not correct.\r\n\r\nThis code\r\n\r\n```\r\nq.and(\r\n    q.criteria(\"width\").equal(10),\r\n    q.criteria(\"height\").equal(1)\r\n);\r\n```\r\nWon't be accepted by the compiler, because `equal()` returns an Object, not a **Criteria**.\r\nA very stupid solution was this.\r\n\r\n```\r\nDatastore ds = this.getValidDatastore(); //pseudocode\r\nQuery myQuery = ds.createQuery(MyEntity.class);\r\nmyQuery.and(\r\n    (Criteria) myQuery.criteria(MyEntity.GREAT_FIELD).exists(),\r\n    (Criteria) myQuery.criteria(MyEntity.GREAT_FIELD).hasAnyOf(myList)); // myList is present\r\nList<MyEntity> myEntities = myQuery.asList();\r\n```\r\n\r\nNow the query looks good and the result is OK. But either the documentation is not complete, or `and()` does not work as expected. "},"comment":{"url":"https://api.github.com/repos/mongodb/morphia/issues/comments/218535186","html_url":"https://github.com/mongodb/morphia/issues/933#issuecomment-218535186","issue_url":"https://api.github.com/repos/mongodb/morphia/issues/933","id":218535186,"user":{"login":"evanchooly","id":195021,"avatar_url":"https://avatars.githubusercontent.com/u/195021?v=3","gravatar_id":"","url":"https://api.github.com/users/evanchooly","html_url":"https://github.com/evanchooly","followers_url":"https://api.github.com/users/evanchooly/followers","following_url":"https://api.github.com/users/evanchooly/following{/other_user}","gists_url":"https://api.github.com/users/evanchooly/gists{/gist_id}","starred_url":"https://api.github.com/users/evanchooly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evanchooly/subscriptions","organizations_url":"https://api.github.com/users/evanchooly/orgs","repos_url":"https://api.github.com/users/evanchooly/repos","events_url":"https://api.github.com/users/evanchooly/events{/privacy}","received_events_url":"https://api.github.com/users/evanchooly/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T17:44:41Z","updated_at":"2016-05-11T17:44:41Z","body":"Are you sure about that?  I just tried it and it worked just fine.  `equal()` actually returns a `T` so this example compiles just fine."}}