QuickFIX/n: FieldNotFoundException when querying group - fix-protocol

I'm currently using QuickFIX/n to build an acceptor service, and I've built an initiator to test the acceptor. I suspect the error I get is due to a bug in the acceptor because the same error occurs with a message that someone else is sending to the service.
In the initiator I build and send an AllocationInstruction as follows:
var fix44Message = new QuickFix.FIX44.AllocationInstruction(
new AllocID(request.Info.AllocationID), EnumHelpers.ParseAllocationTransactionType(request.Info.AllocationTransactionType), EnumHelpers.ParseAllocationType(request.Info.AllocationType),
new AllocNoOrdersType(AllocNoOrdersType.EXPLICIT_LIST_PROVIDED), EnumHelpers.ParseSide(request.Info.Side), new Symbol(request.Info.Symbol), new Quantity(request.Info.Quantity),
new AvgPx(request.Info.AveragePrice), new TradeDate(request.Info.TradeDate.ToString("yyyyMMdd")))
{
SecurityID = new SecurityID(request.Info.SecurityID),
SecurityIDSource = new SecurityIDSource(request.Info.SecurityIDSource),
SecurityExchange = new SecurityExchange(request.Info.SecurityExchange),
Issuer = new Issuer(request.Info.Issuer),
Currency = new Currency(request.Info.Currency),
TransactTime = new TransactTime(request.Info.TransactTime),
SettlDate = new SettlDate(request.Info.SettlementDate.ToString("yyyyMMdd")),
GrossTradeAmt = new GrossTradeAmt(request.Info.GrossTradeAmount),
NetMoney = new NetMoney(request.Info.NetMoney)
};
var group = new QuickFix.FIX44.AllocationInstruction.NoOrdersGroup
{
ClOrdID = new ClOrdID(order.ClOrdID),
OrderID = new OrderID(order.OrderID),
OrderQty = new OrderQty(order.Quantity)
};
fix44Message.AddGroup(group);
In this specific case the message is created with exactly one order group.
In the acceptor I try get the order-groups as follows:
public void OnMessage(QuickFix.FIX44.AllocationInstruction allocation, SessionID sessionID)
{
Console.WriteLine("Order count: " + allocation.NoOrders.getValue());
var orderGroup = new QuickFix.FIX44.AllocationInstruction.NoOrdersGroup();
allocation.GetGroup(1, orderGroup);
info.Orders.Add(new AllocationInstructionOrder
{
ClOrdID = orderGroup.ClOrdID.getValue(),
OrderID = orderGroup.OrderID.getValue(),
Quantity = orderGroup.OrderQty.getValue()
});
}
allocation.NoOrders has a value of 1 as expected. However, when GetGroup() is called with an index of 1 (first group), I get
QuickFix.FieldNotFoundException occurred
HResult=-2146232832
Message=field not found for tag: 73
Source=QuickFix
Field=73
StackTrace:
at QuickFix.FieldMap.GetGroup(Int32 num, Int32 field)
at QuickFix.FieldMap.GetGroup(Int32 num, Group group)
at FIX.FixAcceptorService.AcceptorExchange.OnMessage(AllocationInstruction allocation, SessionID sessionID) in c:\Projects\AdHoc\FIX\FIX\FIX\FixAcceptorService\AcceptorExchange.cs:line 82
InnerException:
This is the FIX message log:
20151008-06:03:57.410 : 8=FIX.4.4 9=65 35=A 34=1 49=TEST 52=20151008-06:03:57.388 56=BAOBAB 98=0 108=30 10=225
20151008-06:03:57.444 : 8=FIX.4.4 9=65 35=A 34=1 49=BAOBAB 52=20151008-06:03:57.440 56=TEST 98=0 108=30 10=214
20151008-06:04:04.162 : 8=FIX.4.4 9=258 35=J 34=2 49=TEST 52=20151008-06:04:04.158 56=BAOBAB 6=9.175 15=ZAR 22=4 48=ZAE0007990962 53=506 54=1 55=R 60=20151008-08:04:04.141 64=20151008 70=080404139 71=0 75=20151008 106=ABC 118=4642.56 207=XJSE 381=4642.56 626=2 857=1 73=1 11=18122977 37=118 38=506 10=251
20151008-06:04:10.876 : 8=FIX.4.4 9=110 35=j 34=2 49=BAOBAB 52=20151008-06:04:10.876 56=TEST 45=2 58=Conditionally Required Field Missing 372=J 380=5 10=127
20151008-06:04:34.890 : 8=FIX.4.4 9=53 35=0 34=3 49=TEST 52=20151008-06:04:34.890 56=BAOBAB 10=176
20151008-06:04:40.894 : 8=FIX.4.4 9=53 35=0 34=3 49=BAOBAB 52=20151008-06:04:40.894 56=TEST 10=177
20151008-06:05:04.909 : 8=FIX.4.4 9=53 35=0 34=4 49=TEST 52=20151008-06:05:04.908 56=BAOBAB 10=175
20151008-06:05:10.910 : 8=FIX.4.4 9=53 35=0 34=4 49=BAOBAB 52=20151008-06:05:10.910 56=TEST 10=165
20151008-06:05:34.921 : 8=FIX.4.4 9=53 35=0 34=5 49=TEST 52=20151008-06:05:34.920 56=BAOBAB 10=173
20151008-06:05:40.924 : 8=FIX.4.4 9=53 35=0 34=5 49=BAOBAB 52=20151008-06:05:40.924 56=TEST 10=174
And finally, the acceptor settings:
[DEFAULT]
SenderCompID=BAOBAB
UseDataDictionary=N
StartTime=00:00:00
EndTime=00:00:00
FileStorePath=C:\Users\bernhard.haussermann\AppData\Local\Temp\FIX_BAOBAB
FileLogPath=C:\Users\bernhard.haussermann\AppData\Local\Temp\FIX_BAOBAB_log
ConnectionType=acceptor
SocketAcceptPort=8030
ResetOnLogon=N
ResetOnLogout=N
ResetOnDisconnect=N
[SESSION]
BeginString=FIX.4.4
TargetCompID=TEST
[SESSION]
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0
TargetCompID=TEST
The C# code above is based on the example on the QuickFIX/n site.
Any ideas?

After downloading the source code for quickfix/n and debugging against it I finally found the cause of the problem!
The acceptor did not interpret the message properly because it did not create a group for the NoOrders (73) tag. The data-dictionary map for looking up group tags was empty, because I used UseDataDictionary=N in my settings.
Changing the acceptor to use a data dictionary solved the problem.
Here is my updated settings string:
[DEFAULT]
SenderCompID=BAOBAB
UseDataDictionary=Y
DataDictionary=C:\Users\bernhard.haussermann\AppData\Local\Temp\FIX44.xml
StartTime=00:00:00
EndTime=00:00:00
FileStorePath=C:\Users\bernhard.haussermann\AppData\Local\Temp\FIX_BAOBAB
FileLogPath=C:\Users\bernhard.haussermann\AppData\Local\Temp\FIX_BAOBAB_log
ConnectionType=acceptor
SocketAcceptPort=8030
ResetOnLogon=N
ResetOnLogout=N
ResetOnDisconnect=N
[SESSION]
BeginString=FIX.4.4
TargetCompID=TEST

Related

Spring batch: items are read again before write when using cursor

I have a spring batch with a step that:
read from table all message in "SCHEDULED" status
process message
update message status to "SENT" or other status according to process result
Using RepositoryItemReader i had the problem that updating items state messed up pagination, so i ended up using JpaCursorItemReader.
Everything goes fine, but now all the items are read again from DB before the update phase (this not happens when using RepositoryItemReader).
Here is my relevant code:
#Autowired
private MessageSenderProcessor messageSenderProcessor;
#Autowired
private GovioMessagesRepository govioMessagesRepository;
public Step getProfileStep(){
return steps.get("getProfileStep")
.<GovioMessageEntity, GovioMessageEntity>chunk(10)
.reader(expiredScheduledDateMessageReader())
.processor(this.messageSenderProcessor)
.writer(messageWriter())
.build();
}
private RepositoryItemWriter<GovioMessageEntity> messageWriter() {
final RepositoryItemWriter<GovioMessageEntity> repositoryItemWriter = new RepositoryItemWriter<>();
repositoryItemWriter.setRepository(govioMessagesRepository);
repositoryItemWriter.setMethodName("save");
return repositoryItemWriter;
}
private ItemReader<GovioMessageEntity> expiredScheduledDateMessageCursor() {
JpaCursorItemReader<GovioMessageEntity> itemReader = new JpaCursorItemReader<>();
itemReader.setQueryString("SELECT msg FROM GovioMessageEntity msg WHERE msg.status = :status AND msg.scheduledExpeditionDate < :now");
itemReader.setEntityManagerFactory(entityManager.getEntityManagerFactory());
itemReader.setSaveState(true);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("status", Status.SCHEDULED);
parameters.put("now", LocalDateTime.now());
itemReader.setParameterValues(parameters);
return itemReader;
}
Here an extract of execution log:
Hibernate: select goviomessa0_.id as id1_0_0_, govioservi1_.id as id1_1_1_, goviomessa0_.amount as amount2_0_0_, goviomessa0_.appio_message_id as appio_me3_0_0_, goviomessa0_.creation_date as creation4_0_0_, goviomessa0_.expedition_date as expediti5_0_0_, goviomessa0_.id_govio_service_instance as id_govi15_0_0_, goviomessa0_.invalid_after_due_date as invalid_6_0_0_, goviomessa0_.last_update_status as last_upd7_0_0_, goviomessa0_.markdown as markdown8_0_0_, goviomessa0_.notice_number as notice_n9_0_0_, goviomessa0_.payee as payee10_0_0_, goviomessa0_.scheduled_expedition_date as schedul11_0_0_, goviomessa0_.status as status12_0_0_, goviomessa0_.subject as subject13_0_0_, goviomessa0_.taxcode as taxcode14_0_0_ from govio_messages goviomessa0_ where goviomessa0_.status=? and goviomessa0_.scheduled_expedition_date<?
2022-11-07 10:03:06,990 INFO [spring_batch_msgsender1] it.govio.msgsender.step.GetProfileProcessor: Sending msg 1
2022-11-07 10:03:06,990 INFO [spring_batch_msgsender2] it.govio.msgsender.step.GetProfileProcessor: Sending msg 2
2022-11-07 10:03:06,990 INFO [spring_batch_msgsender3] it.govio.msgsender.step.GetProfileProcessor: Sending msg 3
....
2022-11-07 10:03:07,171 INFO [spring_batch_msgsender1] it.govio.msgsender.step.GetProfileProcessor: Message sent.
2022-11-07 10:03:07,171 INFO [spring_batch_msgsender2] it.govio.msgsender.step.GetProfileProcessor: Message sent.
2022-11-07 10:03:07,220 INFO [spring_batch_msgsender3]
....
Hibernate: select goviomessa0_.id as id1_0_0_, goviomessa0_.amount as amount2_0_0_, goviomessa0_.appio_message_id as appio_me3_0_0_, goviomessa0_.creation_date as creation4_0_0_, goviomessa0_.expedition_date as expediti5_0_0_, goviomessa0_.id_govio_service_instance as id_govi15_0_0_, goviomessa0_.invalid_after_due_date as invalid_6_0_0_, goviomessa0_.last_update_status as last_upd7_0_0_, goviomessa0_.markdown as markdown8_0_0_, goviomessa0_.notice_number as notice_n9_0_0_, goviomessa0_.payee as payee10_0_0_, goviomessa0_.scheduled_expedition_date as schedul11_0_0_, goviomessa0_.status as status12_0_0_, goviomessa0_.subject as subject13_0_0_, goviomessa0_.taxcode as taxcode14_0_0_ from govio_messages goviomessa0_ where goviomessa0_.id=?
Hibernate: select goviomessa0_.id as id1_0_0_, goviomessa0_.amount as amount2_0_0_, goviomessa0_.appio_message_id as appio_me3_0_0_, goviomessa0_.creation_date as creation4_0_0_, goviomessa0_.expedition_date as expediti5_0_0_, goviomessa0_.id_govio_service_instance as id_govi15_0_0_, goviomessa0_.invalid_after_due_date as invalid_6_0_0_, goviomessa0_.last_update_status as last_upd7_0_0_, goviomessa0_.markdown as markdown8_0_0_, goviomessa0_.notice_number as notice_n9_0_0_, goviomessa0_.payee as payee10_0_0_, goviomessa0_.scheduled_expedition_date as schedul11_0_0_, goviomessa0_.status as status12_0_0_, goviomessa0_.subject as subject13_0_0_, goviomessa0_.taxcode as taxcode14_0_0_ from govio_messages goviomessa0_ where goviomessa0_.id=?
....
Hibernate: update govio_messages set amount=?, appio_message_id=?, creation_date=?, expedition_date=?, id_govio_service_instance=?, invalid_after_due_date=?, last_update_status=?, markdown=?, notice_number=?, payee=?, scheduled_expedition_date=?, status=?, subject=?, taxcode=? where id=?
Hibernate: update govio_messages set amount=?, appio_message_id=?, creation_date=?, expedition_date=?, id_govio_service_instance=?, invalid_after_due_date=?, last_update_status=?, markdown=?, notice_number=?, payee=?, scheduled_expedition_date=?, status=?, subject=?, taxcode=? where id=?
...
So i have those questions:
Why the item is read again after process phase when using cursor?
Can i avoid this?
CursorItemReader as item reader is the right choice for my use case?

how to answer a MassQuoteAck?

i'm trying to get bid and ask a primeXM broker. but i don't know what i'm doing wrong. could anyone show me an example of an answer to Massquote?
As soon as I get a MassQuote response, I'm sending a MassQuoteAsk, but the error "Required tag missing" occurs.
The logs:
ToApp 8=FIX.4.4 |9=86 |35=V |34=2 |49=XXXX|52=20200826-15:10:02.528 |56=XXXX |262=0 |263=1 |264=0 |146=1 |55=USD/JPY |10=205 |
FromApp 8=FIX.4.4 |9=135 |35=i |34=2 |49=XC80 |52=20200826-15:10:02.769 |56=Q097 |117=1 |296=1 |302=0 |295=1 |299=0 |106=10 |134=3000000 |135=1000000 |188=106.11 |190=106.112 |10=048 |
OnMessage MassQuote 8=FIX.4.4 |9=135 |35=i |34=2 |49=XC80 |52=20200826-15:10:02.769 |56=Q097 |117=1 |296=1 |302=0 |295=1 |299=0 |106=10 |134=3000000 |135=1000000 |188=106.11 |190=106.112 |10=048 |
ToApp 8=FIX.4.4 |9=57 |35=b |34=3 |49=XXXX|52=20200826-15:10:02.814 |56=XXXX |117=1 |10=002 |
ToAdmin 8=FIX.4.4 |9=100 |35=3 |34=4 |49=XXXX|52=20200826-15:10:02.931 |56=XXXX |45=3 |58=Required tag missing |371=117 |372=i |373=1 |10=238 |
Request of MarketData:
private void QueryMarketDataRequest() {
MDReqID mdReqId = new MDReqID(GetFreeID);
SubscriptionRequestType subscriptionRequestType =
new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES);
MarketDepth marketDepth = new MarketDepth(0);
MarketDataRequest.NoRelatedSymGroup symbolGroup = new MarketDataRequest.NoRelatedSymGroup();
symbolGroup.Set(new Symbol("USD/JPY"));
MarketDataRequest message = new MarketDataRequest(mdReqId, subscriptionRequestType, marketDepth);
message.AddGroup(symbolGroup);
SendMessage(message);
}
MassQuote message response:
public void OnMessage(MassQuote message, SessionID sessionId) {
_logger.LogDebug($"OnMessage MassQuote {message}");
MassQuoteAcknowledgement m = new MassQuoteAcknowledgement();
m.QuoteID = message.QuoteID;
SendMessage(m);
}
It sounds like you need to get ahold of PrimeXM's connection specification and update your DataDictionary XML file to match it.
For instance, if their spec indicates that they are not going to send 117 in their MassQuote message, then you need remove 117 from the MassQuote definition in your dictionary.
my .cfg was UseDataDictionary=Y, but sometimes it seems that PrimeXM answers MassQuote (MsgType=i) without QuoteID (117), but in my FIX44.xml 117 is set as required. and this was causing the error.
so I changed .cfg UseDataDictionary=N and it stopped giving the error.
I don't know why PrimeXM sends MassQuote without QuoteID, but I think I solved my problem.
Thanks.
dbug: QuickFix.IApplication[0]
FromApp 8=FIX.4.4╔9=95╔35=i╔34=63╔49=XC80╔52=20200826-16:58:12.444╔56=Q097╔106=10╔190=106.008╔295=1╔296=1╔299=0╔302=0╔10=229╔
dbug: QuickFix.IApplication[0]
OnMessage MassQuote 8=FIX.4.4╔9=95╔35=i╔34=63╔49=XC80╔52=20200826-16:58:12.444╔56=Q097╔106=10╔190=106.008╔295=1╔296=1╔299=0╔302=0╔10=229╔
warn: QuickFix.IApplication[0]
field not found for tag: 117

Python (Flask) MongoDB Speed Issue

I have a big speed problem on my website using Flask/MongoDB as backend. A basic request (get 1 user for example) takes about 4 sec to respond.
Here is the python code :
#users_apis.route('/profile/<string:user_id>',methods= ['GET','PUT','DELETE'])
#auth_token_required
def profile(user_id):
if request.method == "GET":
avatar = ''
if user_id == str(current_user.id):
if(current_user.birthday):
age = (date.today().year - current_user.birthday.year)
else:
age = ''
return make_response(jsonify({
"id" : str(current_user.id),
"username" : current_user.username,
"email" : current_user.email,
"first_name": current_user.first_name,
"last_name" : current_user.last_name,
"age" : age,
"birthday" : current_user.birthday,
"gender" : current_user.gender,
"city" : current_user.city,
"country" : current_user.country,
"languages" : current_user.languages,
"description" : current_user.description,
"phone_number" : current_user.phone_number,
"countries_visited" : current_user.countries_visited,
"countries_to_visit" : current_user.countries_to_visit,
"zip_code" : str(current_user.zip_code),
"address" : current_user.address,
"pictures" : current_user.pictures,
"avatar" : "",
"interests" : current_user.interests,
"messages" : current_user.messages,
"invitations" : current_user.invitations,
"events" : current_user.events
}), 200)
And my mongodb database is build like this :
The selected user is nearly empty (has no friends, no events, no pictures...).
class BaseUser(db.Document, UserMixin):
username = db.StringField(max_length=64, unique=True, required=True)
email = db.EmailField(unique=True, required=True)
password = db.StringField(max_length=255, required=True)
active = db.BooleanField(default=True)
joined_on = db.DateTimeField(default=datetime.now())
roles = db.ListField(db.ReferenceField(Role), default=[])
class User(BaseUser)
# Identity
first_name = db.StringField(max_length=255)
last_name = db.StringField(max_length=255)
birthday = db.DateTimeField()
gender = db.StringField(max_length=1,choices=GENDER,default='N')
# Coordinates
address = db.StringField(max_length=255)
zip_code = db.IntField()
city = db.StringField(max_length=64)
region = db.StringField(max_length=64)
country = db.StringField(max_length=32)
phone_number = db.StringField(max_length=18)
# Community
description = db.StringField(max_length=1000)
activities = db.StringField(max_length=1000)
languages = db.ListField(db.StringField(max_length=32))
countries_visited = db.ListField(db.StringField(max_length=32))
countries_to_visit = db.ListField(db.StringField(max_length=32))
interests = db.ListField(db.ReferenceField('Tags'))
friends = db.ListField(db.ReferenceField('User'))
friend_requests = db.ListField(db.ReferenceField('User'))
pictures = db.ListField(db.ReferenceField('Picture'))
events = db.ListField(db.ReferenceField('Event'))
messages = db.ListField(db.ReferenceField('PrivateMessage'))
invitations = db.ListField(db.ReferenceField('Invitation'))
email_validated = db.BooleanField(default=False)
validation_date = db.DateTimeField()
I have a debian serveur with 6Go Ram and 1 vcore, 2,4GHz.
When I check the log for the mongoDB I don't see request that takes more then 378ms (for a search request)
If I use TOP during a request on my server:
I see for 1 sec a 97% CPU use for Python during the request.
When I check the python server output :
I see 4 second between the Option request and the Get Request.
I finally managed to "fix" my issue.
It seems all the problem was due to the #auth_token_required.
Each request done by the front end to the back end with the "headers.append('Authentication-Token',currentUser.token);" created a huge delay.
I replaced #auth_token_required by #login_required.
I m now using cookies.
Hope it helps someone.

mongodb not letting writes go through

Writing to Mongodb via Java Driver. Getting the following error:
com.mongodb.WriteConcernException: { "serverUsed" : "127.0.0.1:27017" , "err" : "_a != -1" , "n" : 0 , "connectionId" : 3 , "ok" : 1.0}
at com.mongodb.CommandResult.getWriteException(CommandResult.java:90)
at com.mongodb.CommandResult.getException(CommandResult.java:79)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:135)
at com.mongodb.DBTCPConnector.access$000(DBTCPConnector.java:39)
at com.mongodb.DBTCPConnector$1.execute(DBTCPConnector.java:186)
at com.mongodb.DBTCPConnector$1.execute(DBTCPConnector.java:181)
at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:210)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:181)
at com.mongodb.DBCollectionImpl.insertWithWriteProtocol(DBCollectionImpl.java:528)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:193)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165)
at com.mongodb.DBCollection.insert(DBCollection.java:161)
at com.mongodb.DBCollection.insert(DBCollection.java:147)
at com.mongodb.DBCollection$insert.call(Unknown Source)
Can't find any reference in docs to "err" : "_a != -1". Any thoughts?
EDIT:
Adding code I used (not all as it relies on other libraries to parse files):
MongoClient mongoClient = new MongoClient()
mongoClient.setWriteConcern(WriteConcern.SAFE)
DB db = mongoClient.getDB("vcf")
List<DBObject> documents = new ArrayList<DBObject>()
DBCollection recordsColl = db.getCollection("records")
//loop through file
BasicDBObject mongoRecord = new BasicDBObject()
//add data to mongoRecord
documents.add(mongoRecord)
//end loop
recordsColl.insert(documents)
mongoClient.close()

Spring-Data-MongoDB - Updates take seconds to complete?

I am using spring data mongodb to interact with my mongodb setup. I was testing different write concerns and noticed that with Unacknowledged write concern, the time for updating 1000 documents was around 5-6 secs even though Unacknowledged write concern doesn't wait for any acknowledgement.
I tested the same with raw java driver and the time was around 40 msec.
What could be cause of this huge time difference between raw java driver and spring data mongodb update?
Note that I am using Unacknowledged write concern and mongodb v2.6.1 with default configurations.
Adding Code Used for comparison:-
Raw Java driver code:-
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB( "testdb" );
DBCollection collection = db.getCollection("product");
WriteResult wr = null;
try {
long start = System.currentTimeMillis();
wr = collection.update(
new BasicDBObject("productId", new BasicDBObject("$gte", 10000000)
.append("$lt", 10001000)),
new BasicDBObject("$inc", new BasicDBObject("price", 100)),
false, true, WriteConcern.UNACKNOWLEDGED);
long end = System.currentTimeMillis();
System.out.println(wr + " Time taken: " + (end - start) + " ms.");
}
Spring Code:-
Config.xml
<mongo:mongo host="localhost" port="27017" />
<mongo:db-factory dbname="testdb" mongo-ref="mongo" />
<bean id="Unacknowledged" class="com.mongodb.WriteConcern">
<constructor-arg name="w" type="int" value="0"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
<property name="writeConcern" ref="Unacknowledged"/>
</bean>
Java Code for update function which is part of ProductDAOImpl:-
public int update(long fromProductId, long toProductId, double changeInPrice)
{
Query query = new Query(new Criteria().andOperator(
Criteria.where("productId").gte(fromProductId),
Criteria.where("productId").lt(toProductId)));
Update update = new Update().inc("price", changeInPrice);
WriteResult writeResult =
mongoTemplate.updateMulti(query, update, Product.class);
return writeResult.getN();
}
Accesing code:-
ProductDAOImpl productDAO = new ProductDAOImpl();
productDAO.setMongoTemplate(mongoTemplate);
long start = System.currentTimeMillis();
productDAO.update(10000000, 10001000, 100);
long end = System.currentTimeMillis();
System.out.println("Time taken = " + (end - start) + " ms.");
Schema:-
{
"_id" : ObjectId("53b64d000cf273a0d95a1a3d"),
"_class" : "springmongo.domain.Product",
"productId" : NumberLong(6),
"productName" : "product6",
"manufacturer" : "company30605739",
"supplier" : "supplier605739",
"category" : "category30605739",
"mfgDate" : ISODate("1968-04-26T05:00:00.881Z"),
"price" : 665689.7224373372,
"tags" : [
"tag82",
"tag61",
"tag17"
],
"reviews" : [
{
"name" : "name528965",
"rating" : 6.5
},
{
"name" : "name818975",
"rating" : 7.5
},
{
"name" : "name436239",
"rating" : 3.9
}
],
"manufacturerAdd" : {
"state" : "state55",
"country" : "country155",
"zipcode" : 718
},
"supplierAdd" : {
"state" : "state69",
"country" : "country69",
"zipcode" : 691986
}
}
Hope it helps.