Announcement Announcement Module
Collapse
No announcement yet.
Spring Mongo Data Query Issue- simple query works in shell but not in source code Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Mongo Data Query Issue- simple query works in shell but not in source code

    Team

    I am totally lost . I have a simple query that works in the mongo shell but not via source code

    I have included app debug log , mongo db logshowing
    Here is source. Any ideas.

    In fact I have two dev stations. On one station the query works. All software versions are the same.

    @Repository
    public interface UsersRespositoryInterface extends MongoRepository<Users, String>{


    List<Users> findByCity(String name);

    List<Users> findByName(String name);

    List<Users> findByCountry(String name);

    }

    ---------- end source ---------------

    app console logging

    2013-01-25 09:05:14,897 DEBUG | main | com.ge.mongodbtest.dao.UserService | method started in UserSErvice findingAllUsers
    2013-01-25 09:05:14,898 DEBUG | main | o.s.data.mongodb.repository.query.MongoQueryCreato r | Created query Query: { "country" : "Tonga"}, Fields: null, Sort: null
    2013-01-25 09:05:14,899 DEBUG | main | org.springframework.data.mongodb.core.MongoTemplat e | find using query: { "country" : "Tonga"} fields: null for class: class com.ge.mongodbtest.domain.Users in collection: users
    2013-01-25 09:05:14,899 DEBUG | main | org.springframework.data.mongodb.core.MongoDbUtils | Getting Mongo Database name=[ratings]
    2013-01-25 09:05:14,900 DEBUG | main | com.ge.mongodbtest.example.MongoDBApp | Finished names getting users - list size>>>0



    Log file from Mongo system showing SpringData Mongo Query
    Fri Jan 25 09:05:14 [conn7] run command admin.$cmd { isMaster: 1 }
    Fri Jan 25 09:05:14 [conn7] command admin.$cmd command: { isMaster: 1 } ntoreturn:1 keyUpdates:0 reslen:90 0ms
    Fri Jan 25 09:05:14 [conn7] query ratings.users ntoreturn:0 keyUpdates:0 locks(micros) r:58 nreturned:0 reslen:20 0ms
    Fri Jan 25 09:05:14 [conn7] query ratings.users query: { city: "South Cyril" } ntoreturn:0 keyUpdates:0 locks(micros) r:134 nreturned:0 reslen:20 0ms
    Fri Jan 25 09:05:14 [conn7] query ratings.users query: { name: "Ernser Wilderman and Predovic" } ntoreturn:0 keyUpdates:0 locks(micros) r:104 nreturned:0 reslen:20 0ms
    Fri Jan 25 09:05:14 [conn7] query ratings.users query: { country: "Tonga" } ntoreturn:0 keyUpdates:0 locks(micros) r:125 nreturned:0 reslen:20 0ms
    Fri Jan 25 09:05:14 [conn7] Socket recv() errno:10054 An existing connection was forcibly closed by the remote host. 127.0.0.1:53994
    Fri Jan 25 09:05:14 [conn7] SocketException: remote: 127.0.0.1:53994 error: 9001 socket exception [1] server [127.0.0.1:53994]
    Fri Jan 25 09:05:14 [conn7] end connection 127.0.0.1:53994 (1 connection now open)
    Fri Jan 25 09:05:43 [DataFileSync] flushing mmaps took 31ms for 3 files



    Results from Query

    db.ratings.users.find({ country: "Tonga" }).pretty();

    "_id" : ObjectId("51028dded5c8d82dcf079e21"),
    "name" : "Ernser Wilderman and Predovic",
    "first_name" : "Jettie",
    "last_name" : "Maggio",
    "prefix" : "Mr.",
    "suffix" : "Group",
    "city" : "South Cyril",
    "city_prefix" : "Lake",
    "city_suffix" : "side",
    "country" : "Tonga",
    "secondary_address" : "Apt. 826",
    "state" : "South Carolina",
    "state_abbr" : "PR",
    "street_address" : "779 Robyn Expressway",
    "street_name" : "Zieme Turnpike",
    "street_suffix" : "Squares",
    "zip_code" : "83735-8233",
    "bs" : "recontextualize global technologies",
    "catch_phrase" : "Versatile optimal paradigm",
    "domain_name" : "weimann.org",
    "domain_suffix" : "org",
    "domain_word" : "bauchstamm",
    "email" : "[email protected]",
    "free_email" : "[email protected]",
    "ip_v4_address" : "71.161.158.246",
    "ip_v6_address" : "9c8:7558:9525:40c0:544d:2362:4fb6:640f",
    "user_name" : "coleman"

  • #2
    Team,

    I found the issue. When I loaded the data. It created a different collection called "ratings.users"

    as below. The code queries against the "users" collection

    // load("users.js");


    // Insert the objects in to the database.
    db.ratings.users.insert(user);

    # show collections

    > use ratings;
    switched to db ratings
    > show collections;
    ratings.users
    system.indexes
    users
    > db.users.find();

    Comment

    Working...
    X