我在MongoDB中有以下文档(2.4.5)
{
"_id" : 235399,
"casts" : {
"crew" : [
{
"_id" : 1186343,
"withBase" : true,
"department" : "Directing",
"job" : "Director",
"name" : "Connie Rasinski"
},
{
"_id" : 86342,
"withBase" : true
}
]
},
"likes" : 0,
"rating" : 0,
"rating_count" : 0,
"release_date" : "1955-11-11"
}
Run Code Online (Sandbox Code Playgroud)
我想从casts.crew中的数组元素中删除withBase.
我试过这个
db.coll.update({_id:235399},{$unset: { "casts.crew.withBase" : 1 } },false,true)
Run Code Online (Sandbox Code Playgroud)
没有改变.
并试过这个..
db.coll.update({_id:235399},{$unset: { "casts.crew" : { $elemMatch: { "withBase": 1 } } } },false,true)
Run Code Online (Sandbox Code Playgroud)
它从文档中删除了整个工作人员阵列.
有人可以提供正确的查询吗?
我有一个有两个日期字段的集合,我试图查询所有相差15天的记录:
{
"_id" : "someid",
"factoryNumber" : 123,
"factoryName" : "some factory name",
"visitType" : "audit",
"personelId" : "somePersonel",
"lastVisit": ISODate("2018-10-30T00:00:00.000+0000"),
"acceptedDate" : ISODate("2018-11-16T00:00:00.000+0000")
}
Run Code Online (Sandbox Code Playgroud)
现在在某些情况下acceptedDate不会出现,所以我需要根据当前日期对其进行评估.不完全确定如何在spring中编写这种类型的查询以获得期望的结果.
Criteria.where("acceptedDate").
(is 15 days past last visit or current date if last visit not present)
Run Code Online (Sandbox Code Playgroud) 有一个场景,其中多个线程在比较代码上有竞争条件。
private int volatile maxValue;
private AtomicInteger currentValue;
public void constructor() {
this.current = new AtomicInteger(getNewValue());
}
public getNextValue() {
while(true) {
int latestValue = this.currentValue.get();
int nextValue = latestValue + 1;
if(latestValue == maxValue) {//Race condition 1
latestValue = getNewValue();
}
if(currentValue.compareAndSet(latestValue, nextValue) {//Race condition 2
return latestValue;
}
}
}
private int getNewValue() {
int newValue = getFromDb(); //not idempotent
maxValue = newValue + 10;
return newValue;
}
Run Code Online (Sandbox Code Playgroud)
问题 :
解决这个问题的显而易见的方法是在 if 条件周围添加同步块/方法。使用并发 api 而不使用任何类型的锁来解决这个问题的其他高效方法是什么?
如何摆脱 while 循环,以便我们可以在没有或更少线程争用的情况下获得下一个值? …
我有一个春季启动kafka应用程序。我的经纪人每隔几天就会被回收一次。旧的经纪人已取消配置,新的经纪人已配置。
我有一个调度程序,每隔几个小时要检查一次代理。我想确保一旦有了新的经纪人,我们就应该重新加载所有与Spring Kafka相关的bean。与KafkaAutoConfiguration非常相似,除了我希望触发代理值更改并以编程方式加载自动配置。
每当将旧的代理替换为新的代理时,如何以编程方式调用自动配置?
我有一个如下文件:
{
"user_id": NumberLong(1),
"updated_at": ISODate("2016-11-17T09:35:56.200Z"),
"created_at": ISODate("2016-11-17T09:35:07.981Z"),
"banners": {
"normal_x970h90": "/images/banners/4/582d79cb3aef567d64621be9/photo-1440700265116-fe3f91810d72.jpg",
"normal_x468h60": "/images/banners/4/582d79cb3aef567d64621be9/photo-1433354359170-23a4ae7338c6.jpg",
"normal_x120h600": "/images/banners/4/582d79cb3aef567d64621be9/photo-1452570053594-1b985d6ea890.jpg"
},
"name": "jghjghjghj",
"budget": "2000",
"plan": null,
"daily_budget": "232323",
"daily_budget_auto": "",
"href": "qls2.ir",
"targets": {
"cats": [
"fun",
"news"
],
"region": "inIran",
"iran_states": null,
"os": "all",
"gold_network": true,
"dont_show_between_1_n_8": true
},
"payment": {
"bank": "mellat",
"tax": "add"
},
"click_cost": "102000",
"status": null
}
Run Code Online (Sandbox Code Playgroud)
我想检查是否budget低于click_cost我在检查查询中的其他参数时:
db.bcamp.aggregate(
[
{
$match:{
$and: [
{"targets.cats":{
"$in" : ["all"]
}
},
{"banners.normal_x970h90":{
"$exists":true
}
}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试查找符合我条件的邻域 - boundries多边形与帖子的坐标相交但我无法做到 - 无法使用let我的pipeline $match
邮政实体的例子:
{
_id: ObjectId,
...,
location: {
...,
coordinates: {
type: 'Point',
coordinates: [number, number]
}
}
};
Run Code Online (Sandbox Code Playgroud)
邻域实体的例子:
{
_id: ObjectId,
...,
boundries: {
type: 'Polygon',
coordinates: [ [ [number, number], [number, number], [number, number], [number, number], [number, number] ] ]
}
};
Run Code Online (Sandbox Code Playgroud)
查询示例我试图"修复":
db.posts.aggregate([
{ $match: { _id: ObjectId('5a562e62100338001218dffa') } },
{
$lookup: {
from: 'neighborhoods',
let: { postCoordinates: '$location.coordinates.coordinates' },
pipeline: [
{
$match: {
boundries: { …Run Code Online (Sandbox Code Playgroud) 从那时起我一直在为肥皂客户工作,我仍然无法理解.
我有这个错误:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter.isOverlaid from class org.apache.cxf.binding.soap.saaj.SAAJStreamWriter
at org.apache.cxf.binding.soap.saaj.SAAJStreamWriter.getPrefix(SAAJStreamWriter.java:79)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:109)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:87)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:67)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:312)
at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:321)
at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:240)
at com.sigetel.web.web.rest.consumer.SoapClient.invoke(SoapClient.java:63)
at com.sigetel.web.web.rest.consumer.SoapClient.main(SoapClient.java:37)
Disconnected from the target VM, address: '127.0.0.1:60128', transport: 'socket'
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我看到它有点普遍,但仍然无法使它工作.
这是我的代码:
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage response;
SOAPBody responseBody;
dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, true);
dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapActionUri);
try {
MessageFactory messageFactory = MessageFactory.newInstance(); …Run Code Online (Sandbox Code Playgroud) 这是我的NetworkInfo集合的示例文档。
{
"_id" : ObjectId("5a37595bd2d9ce37f86d612e"),
"edgeList" : [
{
"networkSource" : {
"sourceId" : "pump1"
},
"networkRelationship" : {},
"networkTarget" : {
"targetId" : "chiller1",
"parentId" : "pump1"
}
},
{
"networkSource" : {
"sourceId" : "chiller1"
},
"networkRelationship" : {},
"networkTarget" : {
"targetId" : "secondaryPump1",
"parentId" : "chiller1"
}
},
{
"networkSource" : {
"sourceId" : "secondaryPump1"
},
"networkRelationship" : {},
"networkTarget" : {
"targetId" : "ahu1",
"parentId" : "secondaryPump1"
}
}
]
Run Code Online (Sandbox Code Playgroud)
}
我尝试使用以下代码为上述文档创建图形查找:
泵1->冷却器1->次级泵1-> ahu1
db.getCollection("NetworkInfo").aggregate([ …Run Code Online (Sandbox Code Playgroud) aggregateMongoTemplate返回的方法AggregationResults<T>,其中T是与mongo集合对应的类.
有时,我们只需要该集合中的单个(例如属性abc)或几个属性(pqr和xyz),具体取决于特定条件.在这些情况下,我们可以将整个集合检索到T类中,也可以创建一个包含properties(abc)或(pqr,xyz)的新类.
有没有办法将这些单个属性映射到List<String>两个属性作为键值对HashMap<String, String>?
我有一种情况,我从聚合中得到一个结果,我以这种格式获取数据。
{
"_id" : ObjectId("5a42432d69cbfed9a410e8ad"),
"bacId" : "BAC0023444",
"cardId" : "2",
"defaultCardOrder" : "2",
"alias" : "Finance",
"label" : "Finance",
"for" : "",
"cardTooltip" : {
"enable" : true,
"text" : ""
},
"dataBlocks" : [
{
"defaultBlockOrder" : "1",
"blockId" : "1",
"data" : "0"
},
{
"defaultBlockOrder" : "2",
"blockId" : "2",
"data" : "0"
},
{
"defaultBlockOrder" : "3",
"blockId" : "3",
"data" : "0"
}
],
"templateBlocks" : [
{
"blockId" : "1",
"label" : "Gross …Run Code Online (Sandbox Code Playgroud) mongodb ×7
java ×5
spring ×2
spring-boot ×2
arrays ×1
comparison ×1
concurrency ×1
criteria ×1
cxf ×1
document ×1
pipeline ×1
soap ×1
spring-kafka ×1
spring-mongo ×1
spring-mvc ×1
web-services ×1