小编bil*_*boc的帖子

Mongodb upsert抛出DuplicateKeyException

当我尝试使用方法[1]插入(增加或插入)文档时,我不时会收到此错误[2].

[1]

public NGram save(final NGram ngram) {
    Criteria cr = where("_id").is(ngram.getNgram())
            .and("f3c").is(ngram.getF3c())
            .and("tokCount").is(ngram.getTokCount())
            .and("first").is(ngram.getFirst())
            ;
    if( ngram.getTokCount() > 1 ) {
        cr.and("second").is(ngram.getSecond());
    }
    if( ngram.getTokCount() > 2 ) {
        cr.and("third").is(ngram.getThird());
    }
    final Query qry = new Query( cr );
    final Update updt = new Update().inc("count", ngram.getCount());
    template.upsert(qry, updt, NGram.class);
    return ngram;
}
Run Code Online (Sandbox Code Playgroud)

[2]

Caused by: org.springframework.dao.DuplicateKeyException: E11000 duplicate key error index: sytrue.ngram.$_id_  dup key: { : "page two" }; nested exception is com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: sytrue.ngram.$_id_ …
Run Code Online (Sandbox Code Playgroud)

spring upsert mongodb

9
推荐指数
1
解决办法
8082
查看次数

mongo:存储库不再有效

我有这个配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/data/mongo
      http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <mongo:repositories base-package="com.x.record.persistence.repo"
        mongo-template-ref="mongoTemplate" />

    <context:component-scan base-package="com.x.record.persistence.impl" />

</beans>
Run Code Online (Sandbox Code Playgroud)

在包中com.x.record.persistence.impl我有一个需要存储库的组件com.x.record.persistence.repo.

这适用于spring-data-mongodb 1.5.2版.RELEASE

如果我升级到大于1.6.0的任何版本.RELEASE(我试过1.6.2和1.7.0)这不再有效.好像mongo存储库扫描不起作用,我收到错误:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'noAuthRecordPersistenceService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.x.record.persistence.repo.RecordRepository com.x.record.persistence.impl.NoAuthRecordPersistenceServiceImpl.repo;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.x.record.persistence.repo.RecordRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. …
Run Code Online (Sandbox Code Playgroud)

spring mongodb

8
推荐指数
1
解决办法
436
查看次数

SDN与Neo4j 2.2x

许多人声称SDN版本3.3.1或4.0.0.RC1应该与neo4j 2.2.x一起使用,但我无法使其工作.

我有这个spring配置配置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:spring-configured />

    <neo4j:config graphDatabaseService="graphDatabaseService" base-package="com.x.protogy.neo4j"/>
    <bean id="graphDatabaseService"
        class="org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase">
      <constructor-arg index="0" value="http://localhost:7476/db/data" />
    </bean>
    <tx:annotation-driven mode="aspectj"
        transaction-manager="transactionManager" />

</beans>
Run Code Online (Sandbox Code Playgroud)

这会产生以下异常:

Caused by: java.lang.ClassNotFoundException: org.neo4j.kernel.impl.nioneo.store.StoreId
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
Run Code Online (Sandbox Code Playgroud)

查看代码清楚地表明:SDN指的是在2.2.x中消除的neo4j库中的一个类:

org.neo4j.kernel.impl.nioneo.store.StoreId
Run Code Online (Sandbox Code Playgroud)

在这种情况下我有什么选择?

spring-data-neo4j

7
推荐指数
2
解决办法
227
查看次数

MongoDB Spring 数据 Criteria.all

在 mongo 控制台中,我有:

> db.test.find({})
{ "_id" : ObjectId("515afcfedba6a529520becfa"), "array" : [ { "key" : "one", "value" : 1 }, { "key" : "two", "value" : 2 } ] }
{ "_id" : ObjectId("515b0e48dba6a529520becfd"), "array" : [ { "key" : "one", "value" : 1 }, { "key" : "two", "value" : 2 }, {"key" :"three", "value" : 3 } ] }


> db.test.find({array: {$all:[{key:'one', value:1}, {key:'two',value:2}]}});
{ "_id" : ObjectId("515afcfedba6a529520becfa"), "array" : [ { "key" : "one", "value" : 1 …
Run Code Online (Sandbox Code Playgroud)

java spring mongodb

2
推荐指数
1
解决办法
3394
查看次数

jquery单击图像,以完整大小打开,再次单击关闭

在我有一个HTML页面<img src='img_thumb.jpg'>.如果不使用任何花哨的jquery滑块插件,我希望能够单击上面的缩略图图像和全尺寸图像,以显示灰色背后的页面内容.对图像的新单击应关闭此图层并显示页面内容.

html javascript css jquery image

-1
推荐指数
1
解决办法
2万
查看次数

标签 统计

mongodb ×3

spring ×3

css ×1

html ×1

image ×1

java ×1

javascript ×1

jquery ×1

spring-data-neo4j ×1

upsert ×1