Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102971

Re: Unable to insert data into MongoDB.

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Unable to insert data into MongoDB.
Date 2016-02-15 17:33 +0100
Organization None
Message-ID <mailman.145.1455554034.22075.python-list@python.org> (permalink)
References <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com> <mailman.50.1455206980.22075.python-list@python.org> <8bb40e3f-57ce-4d5a-a426-6b56cebc8de7@googlegroups.com> <mailman.139.1455536203.22075.python-list@python.org> <ea5105bf-68b9-4999-bbd6-631fd6408d99@googlegroups.com>

Show all headers | View raw


Arjun Srivatsa wrote:

> Hi Peter.
> 
> Thank you for the reply.
> 
> This is the read_server code:
> 
> import socket
> from pymongo import MongoClient
> #import datetime
> import sys
> 
> # Connection to server (PLC) on port 27017
> host = "10.52.124.135"
> port = 27017
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((host, port))
> sys.stdout.write(s.recv(1024))
> 
> 
> And the write_db code:
> 
> from pymongo import MongoClient
> import datetime
> import socket
> import sys
> 
> client = MongoClient('mongodb://localhost:27017/')
> db = client.test_database
> 
> mongodoc = { "data": 'data', "date" : datetime.datetime.utcnow() }
> values = db.values
> values_id = values.insert_one(mongodoc).inserted_id
> 
> 
> So, both these scripts work independently. While, read_server shows the
> output of the actual data from PLC, write_db inserts the sample data into
> the MongoDB.
> 
> I am not sure as to how to combine these both and get the desired output.

What I mean is once you have working scripts

connect_to_mongodb()
while True:
    record = make_fake_data()
    insert_record_into_mongodb(record)

and

connect_to_server()
while True:
    record = read_record_from_server()
    print(record)

you can combine the code in a third script to

connect_to_server()
connect_to_mongodb()
while True:
    record = read_record_from_server()
    insert_record_into_mongodb(record)

and be fairly sure that the combination works, too.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-11 07:12 -0800
  Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-11 08:07 -0800
  Re: Unable to insert data into MongoDB. MRAB <python@mrabarnett.plus.com> - 2016-02-11 16:09 +0000
    Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 02:44 -0800
      Re: Unable to insert data into MongoDB. Peter Otten <__peter__@web.de> - 2016-02-15 12:36 +0100
        Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 07:00 -0800
          Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 07:28 -0800
          Re: Unable to insert data into MongoDB. Peter Otten <__peter__@web.de> - 2016-02-15 17:33 +0100
            Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-16 04:41 -0800
  Re: Unable to insert data into MongoDB. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-11 20:06 -0500

csiph-web