# Without transaction with dgo

**URL:** <https://discuss.dgraph.io/t/without-transaction-with-dgo/3475>\
**Category:** Users\
**Created:** [October 24, 2018, 2:19pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475 "2018-10-24T14:19:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)\
**Post date:** [October 24, 2018, 2:19pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/1 "2018-10-24T14:19:52Z")

</div>

hi,

i realised the example shown in dgo library uses transaction

```auto
txn := dgraphClient.NewTxn()
defer txn.Discard(ctx)

```

is there a way that i query or mutate without transaction?  
means all mutation should be automatically applied, and if any error occurs, those executed mutate should already applied.

please advice

thank you

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [October 24, 2018, 6:53pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/2 "2018-10-24T18:53:27Z")

</div>

There’s a `CommitNow` field in api.Mutation, which you can set.

See here:

> <https://github.com/dgraph-io/dgraph/blob/d4bcecfc12278d4379fe738acfe639ec538ad34b/dgraph/cmd/live/batch.go#L174>

---

<div class="post-metadata">

**Author:** ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)\
**Post date:** [October 25, 2018, 6:15am UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/3 "2018-10-25T06:15:44Z")

</div>

in dgo library, if i set commitnow to true,  
and if i loop the mutate for another object, it will state transaction already commited

do you mean that ive to keep spawning transaction for every mutate call?

in my opinions, i think this isn’t practical.  
I’m also thinking, what if ive billion of records to update?  
if i were to commit in the end, the billion of records , will it slows things down?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [October 25, 2018, 2:11pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/4 "2018-10-25T14:11:18Z")

</div>

> [@u007](#):
>
> is there a way that i query or mutate without transaction?

There’s no way to do that.

> [@u007](#):
>
> do you mean that ive to keep spawning transaction for every mutate call?

All Dgraph operation on all clients depends on transaction. You can create a gigantic operation that will you’ll commit to the end of it all. But you have to learn to do this. In general, it is better to commit immediately.

> [@u007](#):
>
> if i were to commit in the end, the billion of records , will it slows things down?

There’s no issues with that. You have the option to commit now or whenever you want. You are free to set an approach. You just need to know what you doing.

> [@u007](#):
>
> if i set commitnow to true,  
> and if i loop the mutate for another object, it will state transaction already commited

So, do not use commitnow, see the transaction documentation and you’ll understand how to use it without commitnow. [Get started with Dgraph](https://docs.dgraph.io/clients/#create-a-transaction)

Cheers.

---

<div class="post-metadata">

**Author:** ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)\
**Post date:** [October 25, 2018, 3:28pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/5 "2018-10-25T15:28:13Z")

</div>

thank you @MichelDiz  
guess its safe to commit in the end even thou there are many mutation.  
will this effect any memory or disk usage if it incur millions of records?

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [October 25, 2018, 7:27pm UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/6 "2018-10-25T19:27:37Z")

</div>

To correct what @MichelDiz said, you don’t want a txn with a billion mutations in there. Each txn needs to be a good chunk size. You can look at how we’re doing things in live loader. But say, a 1000 RDFs per txn is about the right size.

Yes, you’d need to commit each txn, there’s no way around that. If you want performance of loading a billion things, switch to the bulk loader. Dgraph live loading isn’t designed for that.

---

<div class="post-metadata">

**Author:** ![u007](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/u007/32/1220_2.png) [@u007](https://discuss.dgraph.io/u/u007)\
**Post date:** [October 26, 2018, 10:12am UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/7 "2018-10-26T10:12:17Z")

</div>

Thank you for clarifying.  
Alright probably thousand mutation update per transaction should be good. Its a update on existing record to fix missing predicate for existing okd records

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [November 25, 2018, 10:12am UTC](https://discuss.dgraph.io/t/without-transaction-with-dgo/3475/8 "2018-11-25T10:12:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
