0

所以我想添加一些数据,但它

{
    "_id" : ObjectId("5a0c6748fb3aac66aafe26d7"),
    "picture" : "http://placehold.it/150x150",
    "name" : "Cablam",
    "email" : "leilaware@cablam.com",
    "city" : "Rabat",
    "location" : {
            "type" : "Point",
            "coordinates" : [
                    -6.75778,
                    33.97468
            ]
    }
}

现在,当我尝试仅插入 normale 对象时它可以工作,但是当我尝试包含其他对象的对象以嵌入一对一关系的文档时,它不起作用我发现集合是空的

对于 spring 配置,它是 XML

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <!-- <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> -->
    <constructor-arg name="mongo" ref="mongo"/>
    <constructor-arg name="databaseName" value="yourdb"/>
</bean>

<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
  <property name="host" value="localhost"/>
</bean>

我要保存数据的类

@Repository
public class CustomerDAOImpl implements CustomerDAO {

@Autowired
private MongoTemplate mongoTemp ;

@Override
public List<Customer> getCustomers() {


     MongoOperations mongoOperation ; //= (MongoOperations) appContext.getBean("mongoTemplate");


    Location location = new Location(
            "point", 
            new ArrayList<Double>( Arrays.asList(11111111.1, 00000000.0))
            );

    Shop shop = new Shop("pic link", "superName","superEmail","supercity",location,true );

    // save
    mongoOperation = (MongoOperations) mongoTemp;

    mongoOperation.save(shop);

    //shopRepository.insert(shop);
    // now user object got the created id.
    System.out.println(">>>>>>>> >>> >> 1. use1r : " + shop);
  ....

模型/实体

@Document(collection="shops")
public class Shop {

@Id
private String id;
private String picture;
private String name;
private String email;
private String city;

//@GeoSpatialIndexed(type=GeoSpatialIndexType.GEO_2DSPHERE)
private Location location;

private Boolean isLiked;

/*private Date shownAfter;*/


public Shop(String picture, String name, String email, String city, Location location, Boolean isLiked/*, Date shownAfter*/) {
    super();
    this.picture = picture;
    this.name = name;
    this.email = email;
    this.city = city;
    this.location = location;
    this.isLiked = isLiked;
    //this.shownAfter = shownAfter;
}
...
}

可以帮助我吗

4

0 回答 0