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


Groups > comp.lang.python > #102971

Re: Unable to insert data into MongoDB.

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Unable to insert data into MongoDB.
Date Mon, 15 Feb 2016 17:33:40 +0100
Organization None
Lines 67
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>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de nHxD6yRLvZXl+gmBPKstywE4snMCY2JBSqkprwYD3Dnw==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; 'inserts': 0.07; 'socket': 0.07; 'scripts': 0.09; 'port))': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'output': 0.13; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'skip:v 30': 0.20; 'fairly': 0.22; 'import': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'host': 0.28; 'values': 0.28; 'actual': 0.28; 'record': 0.29; 'code:': 0.29; 'connection': 0.30; 'too.': 0.30; 'code': 0.30; 'skip:s 30': 0.31; 'third': 0.33; 'combination': 0.33; 'skip:d 20': 0.34; 'server': 0.34; 'so,': 0.35; 'reply.': 0.35; 'skip:m 40': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'client': 0.37; 'received:org': 0.37; 'desired': 0.37; 'thank': 0.38; 'mean': 0.38; 'data': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'sample': 0.63
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8092.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102971

Show key headers only | 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