python – Returns the first element nested within an array of a JSON file

I have a MongoDB-hosted JSON file and I want to get the first element of the array array

{
  "_id": "5de9483c65222ef002ad6135",
  "election": "local-min-2015",
  "type": "FeatureCollection",
  "features": (
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": (
          (
            (
              5039258.279933322,
              5142586.1579948
            ),
            (
              5039615.847231327,
              5142411.105566747
            )
          )
        )
      },
      "properties": {
        "1": {
          "Partido Popular": "50.64"
        },
        "2": {
          "Partido Socialista Obrero Espanol": "3.22"
        },
        "3": {
          "Unidos Podemos": "1.29"
        },
        "4": {
          "Ciudadanos": "26.18"
        },
        "5": {
          "Vox": "18.45"
        },
        "id": 96918,
        "parent_id": 96916,
        "common_id": "11.01",
        "common_name": "11.01",
        "has_children": true,
        "shape_type_id": 5,
        "shape_type_name": "Majoritarian District",
        "value": "No Data",
        "color": null,
        "title_location": "Majoritarian District: 11.01",
        "Total Voter Turnout (%)": 55.08
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": (
          (
            (
              5039258.279933322,
              5142586.1579948
            ),
            (
              5039615.847231327,
              5142411.105566747
            )
          )
        )
      },
      "properties": {
        "1": {
          "Partido Popular": "45.64"
        },
        "2": {
          "Partido Socialista Obrero Espanol": "7.22"
        },
        "3": {
          "Unidos Podemos": "2.29"
        },
        "4": {
          "Ciudadanos": "26.18"
        },
        "5": {
          "Vox": "18.45"
        },
        "id": 96919,
        "parent_id": 96916,
        "common_id": "11.01",
        "common_name": "11.01",
        "has_children": true,
        "shape_type_id": 5,
        "shape_type_name": "Majoritarian District",
        "value": "No Data",
        "color": null,
        "title_location": "Majoritarian District: 11.01",
        "Total Voter Turnout (%)": 55.08
      }
    }
  )
}

I tried the following:

import pymongo
from bson.son import SON
import json

import os

client = pymongo.MongoClient("mongodb://localhost:27017/")

db = client("Richmond")

collection = db('Collection')

# select the documents where the field features contains the field 0
cursor = collection.find(
    { "election": "local-maj-2017" },
    { "features.0": 1 }#, "type": 0, "election": 0, "_id": 0 } # get the very first item of the features array
)

for doc in cursor:
    print(doc)

But it brings me back:

(base) C:UsersantoiDocumentsProgrammingRichmondMongo>python query_mongdb.py
{'_id': ObjectId('5de9483c65222ef002ad6135'), 'features': ({}, {})}

How can I query and filter a MongoDB-hosted JSON file with Python?

I have a JSON file that I host in Mango and I want to get some of its elements. Here is the file

{
  "_id": "5de9483c65222ef002ad6135",
  "election": "local-min-2015",
  "type": "FeatureCollection",
  "features": (
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": (
          (
            (
              5039258.279933322,
              5142586.1579948
            ),
            (
              5039615.847231327,
              5142411.105566747
            )
          )
        )
      },
      "properties": {
        "1": {
          "Partido Popular": "50.64"
        },
        "2": {
          "Partido Socialista Obrero Espanol": "3.22"
        },
        "3": {
          "Unidos Podemos": "1.29"
        },
        "4": {
          "Ciudadanos": "26.18"
        },
        "5": {
          "Vox": "18.45"
        },
        "id": 96918,
        "parent_id": 96916,
        "common_id": "11.01",
        "common_name": "11.01",
        "has_children": true,
        "shape_type_id": 5,
        "shape_type_name": "Majoritarian District",
        "value": "No Data",
        "color": null,
        "title_location": "Majoritarian District: 11.01",
        "Total Voter Turnout (%)": 55.08
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": (
          (
            (
              5039258.279933322,
              5142586.1579948
            ),
            (
              5039615.847231327,
              5142411.105566747
            )
          )
        )
      },
      "properties": {
        "1": {
          "Partido Popular": "45.64"
        },
        "2": {
          "Partido Socialista Obrero Espanol": "7.22"
        },
        "3": {
          "Unidos Podemos": "2.29"
        },
        "4": {
          "Ciudadanos": "26.18"
        },
        "5": {
          "Vox": "18.45"
        },
        "id": 96919,
        "parent_id": 96916,
        "common_id": "11.01",
        "common_name": "11.01",
        "has_children": true,
        "shape_type_id": 5,
        "shape_type_name": "Majoritarian District",
        "value": "No Data",
        "color": null,
        "title_location": "Majoritarian District: 11.01",
        "Total Voter Turnout (%)": 55.08
      }
    }
  )
}

And I would like to get:

{
  "0": {
    "parties": (
      {
        "Partido Popular": 50.64
      },
      {
        "Partido Socialista Obrero Espanol": 3.22
      },
      {
        "Unidos Podemos": 1.29
      },
      {
        "Ciudadanos": 26.18
      },
      {
        "Vox": 18.45
      }
    ),
    "id": 96918
  },
  "1": {
    "parties": (
      {
        "Partido Popular": 45.64
      },
      {
        "Partido Socialista Obrero Espanol": 7.22
      },
      {
        "Unidos Podemos": 2.29
      },
      {
        "Ciudadanos": 26.18
      },
      {
        "Vox": 18.45
      }
    ),
    "id": 96919
  }
}

To this day I have tried to get the "features", but I have a problem:

import pymongo
from bson.son import SON
import json

import os

client = pymongo.MongoClient("mongodb://localhost:27017/")

db = client("Richmond")

collection = db('Collection')

# select the documents where the field features contains the field 0
cursor = db.collection.find(
    {"_id": "5de9483c65222ef002ad613"},
    { "features": 1, "type": 0, "election": 0, "_id": 0 }
)

for doc in cursor:
    print(doc)

The cmd gives me back:

(base) C:UsersantoiDocumentsProgrammingRichmondMongo>python query_mongdb.py
Traceback (most recent call last):
  File "query_mongdb.py", line 20, in 
    for doc in cursor:
  File "C:ProgramDataAnaconda3libsite-packagespymongocursor.py", line 1156, in next
    if len(self.__data) or self._refresh():
  File "C:ProgramDataAnaconda3libsite-packagespymongocursor.py", line 1073, in _refresh
    self.__send_message(q)
  File "C:ProgramDataAnaconda3libsite-packagespymongocursor.py", line 955, in __send_message
    address=self.__address)
  File "C:ProgramDataAnaconda3libsite-packagespymongomongo_client.py", line 1347, in _run_operation_with_response
    exhaust=exhaust)
  File "C:ProgramDataAnaconda3libsite-packagespymongomongo_client.py", line 1465, in _retryable_read
    return func(session, server, sock_info, slave_ok)
  File "C:ProgramDataAnaconda3libsite-packagespymongomongo_client.py", line 1341, in _cmd
    unpack_res)
  File "C:ProgramDataAnaconda3libsite-packagespymongoserver.py", line 136, in run_operation_with_response
    _check_command_response(first)
  File "C:ProgramDataAnaconda3libsite-packagespymongohelpers.py", line 159, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: Projection cannot have a mix of inclusion and exclusion.

select – Word file executing an SQL command – How do I find the SQL source database?

A Word 2013 file has a merge feature that is activated whenever it is open. It is "SELECT * FROM & # 39; database & # 39;".

Since the final results contain errors (the final Word document feeds come from the wrong field names), I'd like to edit the database to change a few things.

The problem is that I have the & # 39; database & # 39; can not find, because it is not in the same folder as the Word file mentioned above.

We use Access 2003 and this code was created by a person who does not work with us anymore.

Is there a way to determine the source database from the Word file (Word 2013 uses only Access for Office 2003)?

Many thanks.

web – Why does React not recognize the CSS file linked in Index.html?

I've created a meme generator with React as an early project to learn the basics. I have 6 files in my "mememaker" folder on my desktop that I created with "create-react-app". These include: index.html, the parent file that appears, pointing to style.css and index.js. Index.js simply renders the App.js component, which in turn has two child components, the page header and the meme generator itself (which works by writing text to an image returned by an API). Everything seems fine, except for the fact that the styling of "style.css" does not appear to be applied to the page. It looks so terrible.

The code in the files is fine, since all functions are present, but none of the CSS is applied in style.css. I suspect that something is wrong with the file path or the commands I use to create the file (which incidentally only runs once in the src npm start folder).

I have been trying for days to get this working – please help!

Many thanks πŸ™‚

wp admin – WordPress does not reflect the changes I made to a particular file via FTP

Hello, I am new to WordPress. Please let me know if I have omitted important information.

I've just switched from my local host to Online: There were a few bumps, but after repairing some paths, everything seems to be alright. Except for the search results page (and I think I know why).

I wanted more search results to be displayed, ie in Settings > Reading I have updated the number of posts on a page. However now if i update search.phpthe changes will not be reflected on the live site. My uninformed theory is that, because I changed a setting through the wp-admin panel, I somehow cached a recent version of myself search.php and use that instead of the file I'm updating and reloading.

I know that this is probably wrong, but I have no idea why any changes I make to the file are not taken. It's the only page I have this problem with. Changes that I make to other files are displayed immediately.

TO UPDATE: WordPress apparently creates a temporary file when you search for something with the snail /?s=searchterm: So I suspect that whatever creates this file refers to an old version of search.php – If I'm right, how do I fix it?

Command line – Find and replace folder and file names with incompatible Windows characters

My Ubuntu (18.04) drive is synchronized with a Windows drive. Some of my Ubuntu folder and file names contain characters that are not allowed in Windows. This causes synchronization problems. I want to find these characters and either remove them from the file / folder names or replace them with an "x".

How can I do it fast?

Here are the characters forbidden in Windows (modified after Christopher Oezbek's answer):

< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
 (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

To delete a custom file from the upload directory when you delete its post

I save an uploaded attachment in a custom directory below wp-content/uploads/my-directory/ and save its value in wp_postmeta Table. When I delete the post, the attached file is not deleted from the path.

So I tried to connect to that delete_post Tick ​​to clear the file from the path:

Unfortunately, the file is not deleted from the directory. πŸ™

What can I do?